[PATCH] D79277: [Attributor] Bitcast constant to the returned value type if it has different type
Sergey Dmitriev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 1 17:18:48 PDT 2020
sdmitriev created this revision.
sdmitriev added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, uenoku, hiraditya.
Herald added a reviewer: sstefan1.
Herald added a reviewer: uenoku.
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D79277
Files:
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
llvm/test/Transforms/Attributor/returned_crash.ll
Index: llvm/test/Transforms/Attributor/returned_crash.ll
===================================================================
--- llvm/test/Transforms/Attributor/returned_crash.ll
+++ 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
+}
Index: llvm/lib/Transforms/IPO/AttributorAttributes.cpp
===================================================================
--- llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -4534,6 +4534,9 @@
for (ReturnInst *RI : RetInsts) {
if (RI->getFunction() != getAnchorScope())
continue;
+ if (C->getType() != RI->getReturnValue()->getType())
+ C = ConstantExpr::getBitCast(C,
+ RI->getReturnValue()->getType());
LLVM_DEBUG(dbgs() << "[ValueSimplify] " << V << " -> " << *C
<< " in " << *RI << " :: " << *this << "\n");
if (A.changeUseAfterManifest(RI->getOperandUse(0), *C))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79277.261576.patch
Type: text/x-patch
Size: 1937 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200502/1ea48d13/attachment.bin>
More information about the llvm-commits
mailing list