[Attributor] Do not set 'returned' attribute for arguments that cannot be bitcasted...
authorSergey Dmitriev <serguei.n.dmitriev@intel.com>
Sat, 25 Apr 2020 16:33:50 +0000 (09:33 -0700)
committerSergey Dmitriev <serguei.n.dmitriev@intel.com>
Sat, 25 Apr 2020 16:49:40 +0000 (09:49 -0700)
Reviewers: jdoerfert, sstefan1, uenoku

Reviewed By: jdoerfert

Subscribers: hiraditya, uenoku, llvm-commits

Tags: #llvm

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

llvm/lib/Transforms/IPO/AttributorAttributes.cpp
llvm/test/Transforms/Attributor/returned_crash.ll [new file with mode: 0644]

index 8573040..aeb1029 100644 (file)
@@ -906,10 +906,13 @@ ChangeStatus AAReturnedValuesImpl::manifest(Attributor &A) {
 
   // 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();
diff --git a/llvm/test/Transforms/Attributor/returned_crash.ll b/llvm/test/Transforms/Attributor/returned_crash.ll
new file mode 100644 (file)
index 0000000..d9af2e1
--- /dev/null
@@ -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
+}