From 589b4cb58778822b4e28a14dcd22d35f0c73a892 Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Fri, 11 Oct 2019 01:45:32 +0000 Subject: [PATCH] [Attributor][FIX] Do not replace musstail calls with constant git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@374498 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/Attributor.cpp | 2 +- test/Transforms/FunctionAttrs/arg_returned.ll | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/IPO/Attributor.cpp b/lib/Transforms/IPO/Attributor.cpp index c6de94beaf0..4b393539813 100644 --- a/lib/Transforms/IPO/Attributor.cpp +++ b/lib/Transforms/IPO/Attributor.cpp @@ -997,7 +997,7 @@ ChangeStatus AAReturnedValuesImpl::manifest(Attributor &A) { // Callback to replace the uses of CB with the constant C. auto ReplaceCallSiteUsersWith = [](CallBase &CB, Constant &C) { - if (CB.getNumUses() == 0) + if (CB.getNumUses() == 0 || CB.isMustTailCall()) return ChangeStatus::UNCHANGED; CB.replaceAllUsesWith(&C); return ChangeStatus::CHANGED; diff --git a/test/Transforms/FunctionAttrs/arg_returned.ll b/test/Transforms/FunctionAttrs/arg_returned.ll index e9cf2d81f11..99b6762a5c8 100644 --- a/test/Transforms/FunctionAttrs/arg_returned.ll +++ b/test/Transforms/FunctionAttrs/arg_returned.ll @@ -830,6 +830,11 @@ define i32* @use_const() #0 { ; CHECK: ret i32* bitcast (i8* @G to i32*) ret i32* %c } +define i32* @dont_use_const() #0 { + %c = musttail call i32* @ret_const() + ; CHECK: ret i32* %c + ret i32* %c +} attributes #0 = { noinline nounwind uwtable }