Value *llvm::SimplifyCall(CallBase *Call, const SimplifyQuery &Q) {
Value *Callee = Call->getCalledValue();
+ // musttail calls can only be simplified if they are also DCEd.
+ // As we can't guarantee this here, don't simplify them.
+ if (Call->isMustTailCall())
+ return nullptr;
+
// call undef -> undef
// call null -> undef
if (isa<UndefValue>(Callee) || isa<ConstantPointerNull>(Callee))
break;
case Instruction::Call: {
Result = SimplifyCall(cast<CallInst>(I), Q);
+ // Don't perform known bits simplification below for musttail calls.
+ if (cast<CallInst>(I)->isMustTailCall())
+ return Result;
break;
}
case Instruction::Freeze:
%x = call i32 @passthru_i32(i32 %arg)
ret i32 %x
}
+
+define i32 @returned_const_int_arg_musttail(i32 %arg) {
+; CHECK-LABEL: @returned_const_int_arg_musttail(
+; CHECK-NEXT: [[X:%.*]] = musttail call i32 @passthru_i32(i32 42)
+; CHECK-NEXT: ret i32 [[X]]
+;
+ %x = musttail call i32 @passthru_i32(i32 42)
+ ret i32 %x
+}
+
+define i32 @returned_var_arg_musttail(i32 %arg) {
+; CHECK-LABEL: @returned_var_arg_musttail(
+; CHECK-NEXT: [[X:%.*]] = musttail call i32 @passthru_i32(i32 [[ARG:%.*]])
+; CHECK-NEXT: ret i32 [[X]]
+;
+ %x = musttail call i32 @passthru_i32(i32 %arg)
+ ret i32 %x
+}
+
+define i32 @call_undef_musttail() {
+; CHECK-LABEL: @call_undef_musttail(
+; CHECK-NEXT: [[X:%.*]] = musttail call i32 undef()
+; CHECK-NEXT: ret i32 [[X]]
+;
+ %x = musttail call i32 undef()
+ ret i32 %x
+}