]> granicus.if.org Git - llvm/commitdiff
[Attributor][Fix] Use right type to replace expressions
authorJohannes Doerfert <jdoerfert@anl.gov>
Sat, 14 Sep 2019 02:57:50 +0000 (02:57 +0000)
committerJohannes Doerfert <jdoerfert@anl.gov>
Sat, 14 Sep 2019 02:57:50 +0000 (02:57 +0000)
Summary: This should be obsolete once the functionality in D66967 is integrated.

Reviewers: uenoku, sstefan1

Subscribers: hiraditya, bollu, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D67231

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@371915 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/Attributor.cpp
test/Transforms/FunctionAttrs/arg_returned.ll

index 94ed7003c965c923cd8bf4fcf02e0cc8f1f4faae..b9f943e4772e692fffd6f28172f62a765059bd0c 100644 (file)
@@ -874,12 +874,17 @@ ChangeStatus AAReturnedValuesImpl::manifest(Attributor &A) {
     if (Function *F = dyn_cast<Function>(&AnchorValue)) {
       for (const Use &U : F->uses())
         if (CallBase *CB = dyn_cast<CallBase>(U.getUser()))
-          if (CB->isCallee(&U))
-            Changed = ReplaceCallSiteUsersWith(*CB, *RVC) | Changed;
+          if (CB->isCallee(&U)) {
+            Constant *RVCCast =
+                ConstantExpr::getTruncOrBitCast(RVC, CB->getType());
+            Changed = ReplaceCallSiteUsersWith(*CB, *RVCCast) | Changed;
+          }
     } else {
       assert(isa<CallBase>(AnchorValue) &&
              "Expcected a function or call base anchor!");
-      Changed = ReplaceCallSiteUsersWith(cast<CallBase>(AnchorValue), *RVC);
+      Constant *RVCCast =
+          ConstantExpr::getTruncOrBitCast(RVC, AnchorValue.getType());
+      Changed = ReplaceCallSiteUsersWith(cast<CallBase>(AnchorValue), *RVCCast);
     }
     if (Changed == ChangeStatus::CHANGED)
       STATS_DECLTRACK(UniqueConstantReturnValue, FunctionReturn,
index 6e57475c57966260f990c502ed3e2213703e1bf0..95871ff7d34e2ae1913073622eece70a41dfb510 100644 (file)
@@ -827,6 +827,17 @@ define i32 @exact(i32* %a) {
   ret i32 %add3
 }
 
+@G = external global i8
+define i32* @ret_const() #0 {
+  %bc = bitcast i8* @G to i32*
+  ret i32* %bc
+}
+define i32* @use_const() #0 {
+  %c = call i32* @ret_const()
+  ; CHECK: ret i32* bitcast (i8* @G to i32*)
+  ret i32* %c
+}
+
 attributes #0 = { noinline nounwind uwtable }
 
 ; BOTH-NOT: attributes #