enable overapproximation of unknown intrinsics
MODIFY
llvm_util/llvm2alive.cpp
llvm_util/llvm2alive.cpp
@@ -244,7 +244,7 @@ public:
RETURN_IDENTIFIER(make_unique<Freeze>(*ty, value_name(i), *val));
}
- RetTy visitCallInst(llvm::CallInst &i) {
+ RetTy visitCallInst(llvm::CallInst &i, bool approx = false) {
vector<Value *> args;
for (auto &arg : i.args()) {
auto a = get_operand(arg);
@@ -253,9 +253,18 @@ public:
args.emplace_back(a);
}
- auto [call_val, attrs, param_attrs, approx] = known_call(i, TLI, *BB, args);
- if (call_val)
- RETURN_IDENTIFIER(move(call_val));
+ FnAttrs attrs;
+ vector<ParamAttrs> param_attrs;
+ if (!approx) {
+ // call_val, attrs, param_attrs, approx
+ auto known = known_call(i, TLI, *BB, args);
+ if (get<0>(known))
+ RETURN_IDENTIFIER(move(get<0>(known)));
+
+ attrs = move(get<1>(known));
+ param_attrs = move(get<2>(known));
+ approx = get<3>(known);
+ }
auto fn = i.getCalledFunction();
if (!fn) // TODO: support indirect calls
@@ -827,7 +836,8 @@ public:
case llvm::Intrinsic::vector_reduce_umin: op = UnaryReductionOp::UMin; break;
default: UNREACHABLE();
}
- RETURN_IDENTIFIER(make_unique<UnaryReductionOp>(*ty, value_name(i), *val, op));
+ RETURN_IDENTIFIER(
+ make_unique<UnaryReductionOp>(*ty, value_name(i), *val, op));
}
case llvm::Intrinsic::fshl:
case llvm::Intrinsic::fshr:
@@ -913,7 +923,7 @@ public:
default:
break;
}
- return error(i);
+ return visitCallInst(i, true);
}
RetTy visitExtractElementInst(llvm::ExtractElementInst &i) {

MODIFY
tests/alive-tv/bugs/pr29034-unroll.tgt.ll
tests/alive-tv/bugs/pr29034-unroll.tgt.ll
@@ -61,7 +61,7 @@ while.cond2: ; preds = %while.cond2.backedg
sw.bb: ; preds = %while.cond2
%7 = load i32, i32* %file_num9, align 1
- %call6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %7)
+ %call6 = call i32 (i8*, ...) @myprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %while.cond2.backedge
sw.bb7: ; preds = %while.cond2
@@ -90,4 +90,4 @@ declare i32 @music_decoder_init(%struct._MUSIC_OP_API_**)
declare i32 @music_play_api(%struct._MUSIC_OP_API_*, i32, i32, i32, i8*)
-declare i32 @printf(i8* nocapture readonly, ...)
\ No newline at end of file
+declare i32 @myprintf(i8* nocapture readonly, ...)

ADD
tests/alive-tv/unknown-intrinsic-fail.srctgt.ll
+; ERROR: Couldn't prove the correctness of the transformation
+
+declare i8* @llvm.thread.pointer()
+
+define i8* @src() {
+ %call = call i8* @llvm.thread.pointer()
+ ret i8* %call
+}
+define i8* @tgt() {
+ ret i8* null
+}

ADD
tests/alive-tv/unknown-intrinsic.srctgt.ll
+declare i8* @llvm.thread.pointer()
+
+define i8* @f() {
+ %call = call i8* @llvm.thread.pointer()
+ ret i8* %call
+}

enable overapproximation of unknown intrinsics