Skip to content

Commit 67aed14

Browse files
committed
[Attributor] Do not set 'returned' attribute for arguments that cannot be bitcasted to function result
Reviewers: jdoerfert, sstefan1, uenoku Reviewed By: jdoerfert Subscribers: hiraditya, uenoku, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78828
1 parent f31db76 commit 67aed14

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -906,10 +906,13 @@ ChangeStatus AAReturnedValuesImpl::manifest(Attributor &A) {
906906

907907
// If the assumed unique return value is an argument, annotate it.
908908
if (auto *UniqueRVArg = dyn_cast<Argument>(UniqueRV.getValue())) {
909-
// TODO: This should be handled differently!
910-
this->AnchorVal = UniqueRVArg;
911-
this->KindOrArgNo = UniqueRVArg->getArgNo();
912-
Changed = IRAttribute::manifest(A);
909+
if (UniqueRVArg->getType()->canLosslesslyBitCastTo(
910+
getAssociatedFunction()->getReturnType())) {
911+
// TODO: This should be handled differently!
912+
this->AnchorVal = UniqueRVArg;
913+
this->KindOrArgNo = UniqueRVArg->getArgNo();
914+
Changed = IRAttribute::manifest(A);
915+
}
913916
} else if (auto *RVC = dyn_cast<Constant>(UniqueRV.getValue())) {
914917
// We can replace the returned value with the unique returned constant.
915918
Value &AnchorValue = getAnchorValue();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
; RUN: opt -attributor -S %s | FileCheck %s
2+
; RUN: opt -passes=attributor -S %s | FileCheck %s
3+
;
4+
; CHECK: define i32 addrspace(1)* @foo(i32 addrspace(4)* nofree readnone %arg)
5+
define i32 addrspace(1)* @foo(i32 addrspace(4)* %arg) {
6+
entry:
7+
%0 = addrspacecast i32 addrspace(4)* %arg to i32 addrspace(1)*
8+
ret i32 addrspace(1)* %0
9+
}

0 commit comments

Comments
 (0)