// 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();
--- /dev/null
+; 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
+}