[llvm] 0f70f73 - [Attributor] Bitcast constant to the returned value type if it has different type

Sergey Dmitriev via llvm-commits llvm-commits at lists.llvm.org
Sun May 3 11:51:24 PDT 2020


Author: Sergey Dmitriev
Date: 2020-05-03T11:46:13-07:00
New Revision: 0f70f733080e96a45783c59d99e04eecfb2426ca

URL: https://github.com/llvm/llvm-project/commit/0f70f733080e96a45783c59d99e04eecfb2426ca
DIFF: https://github.com/llvm/llvm-project/commit/0f70f733080e96a45783c59d99e04eecfb2426ca.diff

LOG: [Attributor] Bitcast constant to the returned value type if it has different type

Reviewers: jdoerfert, sstefan1, uenoku

Reviewed By: jdoerfert

Subscribers: hiraditya, uenoku, llvm-commits

Tags: #llvm

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

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/AttributorAttributes.cpp
    llvm/test/Transforms/Attributor/returned_crash.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 6f14ad13027b..b9adc0e981cd 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -4532,9 +4532,13 @@ struct AAValueSimplifyReturned : AAValueSimplifyImpl {
             for (ReturnInst *RI : RetInsts) {
               if (RI->getFunction() != getAnchorScope())
                 continue;
-              LLVM_DEBUG(dbgs() << "[ValueSimplify] " << V << " -> " << *C
+              auto *RC = C;
+              if (RC->getType() != RI->getReturnValue()->getType())
+                RC = ConstantExpr::getBitCast(RC,
+                                              RI->getReturnValue()->getType());
+              LLVM_DEBUG(dbgs() << "[ValueSimplify] " << V << " -> " << *RC
                                 << " in " << *RI << " :: " << *this << "\n");
-              if (A.changeUseAfterManifest(RI->getOperandUse(0), *C))
+              if (A.changeUseAfterManifest(RI->getOperandUse(0), *RC))
                 Changed = ChangeStatus::CHANGED;
             }
             return true;

diff  --git a/llvm/test/Transforms/Attributor/returned_crash.ll b/llvm/test/Transforms/Attributor/returned_crash.ll
index d9af2e180340..6b4b9a32d79e 100644
--- a/llvm/test/Transforms/Attributor/returned_crash.ll
+++ b/llvm/test/Transforms/Attributor/returned_crash.ll
@@ -1,9 +1,23 @@
 ; RUN: opt -attributor -S %s | FileCheck %s
 ; RUN: opt -passes=attributor -S %s | FileCheck %s
-;
-; CHECK: define i32 addrspace(1)* @foo(i32 addrspace(4)* nofree readnone %arg)
+
+ at var = internal global [1 x i32] undef
+
+; CHECK-LABEL: define i32 addrspace(1)* @foo(i32 addrspace(4)* nofree readnone %arg)
 define i32 addrspace(1)* @foo(i32 addrspace(4)* %arg) {
 entry:
   %0 = addrspacecast i32 addrspace(4)* %arg to i32 addrspace(1)*
   ret i32 addrspace(1)* %0
 }
+
+define i32* @func1() {
+  %ptr = call i32* @func1a([1 x i32]* @var)
+  ret i32* %ptr
+}
+
+; CHECK-LABEL: define internal nonnull align 4 dereferenceable(4) i32* @func1a()
+; CHECK-NEXT: ret i32* getelementptr inbounds ([1 x i32], [1 x i32]* @var, i32 0, i32 0)
+define internal i32* @func1a([1 x i32]* %arg) {
+  %ptr = getelementptr inbounds [1 x i32], [1 x i32]* %arg, i64 0, i64 0
+  ret i32* %ptr
+}


        


More information about the llvm-commits mailing list