[PATCH] D78828: [Attributor] Do not set 'returned' attribute for arguments that cannot be bitcasted to function result
Sergey Dmitriev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 25 10:04:56 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG67aed1469b0f: [Attributor] Do not set 'returned' attribute for arguments that cannot be… (authored by sdmitriev).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D78828/new/
https://reviews.llvm.org/D78828
Files:
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
llvm/test/Transforms/Attributor/returned_crash.ll
Index: llvm/test/Transforms/Attributor/returned_crash.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/Attributor/returned_crash.ll
@@ -0,0 +1,9 @@
+; 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)
+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
+}
Index: llvm/lib/Transforms/IPO/AttributorAttributes.cpp
===================================================================
--- llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -906,10 +906,13 @@
// If the assumed unique return value is an argument, annotate it.
if (auto *UniqueRVArg = dyn_cast<Argument>(UniqueRV.getValue())) {
- // TODO: This should be handled differently!
- this->AnchorVal = UniqueRVArg;
- this->KindOrArgNo = UniqueRVArg->getArgNo();
- Changed = IRAttribute::manifest(A);
+ if (UniqueRVArg->getType()->canLosslesslyBitCastTo(
+ getAssociatedFunction()->getReturnType())) {
+ // TODO: This should be handled differently!
+ this->AnchorVal = UniqueRVArg;
+ this->KindOrArgNo = UniqueRVArg->getArgNo();
+ Changed = IRAttribute::manifest(A);
+ }
} else if (auto *RVC = dyn_cast<Constant>(UniqueRV.getValue())) {
// We can replace the returned value with the unique returned constant.
Value &AnchorValue = getAnchorValue();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78828.260119.patch
Type: text/x-patch
Size: 1619 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200425/974f3f62/attachment.bin>
More information about the llvm-commits
mailing list