[llvm] r248422 - Remove handling of AddrSpaceCast in stripAndAccumulateInBoundsConstantOffsets

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 23 12:48:44 PDT 2015


Author: reames
Date: Wed Sep 23 14:48:43 2015
New Revision: 248422

URL: http://llvm.org/viewvc/llvm-project?rev=248422&view=rev
Log:
Remove handling of AddrSpaceCast in stripAndAccumulateInBoundsConstantOffsets

Patch by: simoncook

Unlike BitCasts, AddrSpaceCasts do not always produce an output the same size as its input, which was previously assumed. This fixes cases where two address spaces do not have the same size pointer, as an assertion failure would occur when trying to prove deferenceability.  LoopUnswitch is used in the particular test, but LICM also exhibits the same problem.

Differential Revision: http://reviews.llvm.org/D13008


Added:
    llvm/trunk/test/Transforms/LoopUnswitch/2015-09-18-Addrspace.ll
Modified:
    llvm/trunk/lib/IR/Value.cpp

Modified: llvm/trunk/lib/IR/Value.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Value.cpp?rev=248422&r1=248421&r2=248422&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Value.cpp (original)
+++ llvm/trunk/lib/IR/Value.cpp Wed Sep 23 14:48:43 2015
@@ -490,8 +490,7 @@ Value *Value::stripAndAccumulateInBounds
         return V;
       Offset = GEPOffset;
       V = GEP->getPointerOperand();
-    } else if (Operator::getOpcode(V) == Instruction::BitCast ||
-               Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
+    } else if (Operator::getOpcode(V) == Instruction::BitCast) {
       V = cast<Operator>(V)->getOperand(0);
     } else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
       V = GA->getAliasee();

Added: llvm/trunk/test/Transforms/LoopUnswitch/2015-09-18-Addrspace.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopUnswitch/2015-09-18-Addrspace.ll?rev=248422&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/LoopUnswitch/2015-09-18-Addrspace.ll (added)
+++ llvm/trunk/test/Transforms/LoopUnswitch/2015-09-18-Addrspace.ll Wed Sep 23 14:48:43 2015
@@ -0,0 +1,28 @@
+; RUN: opt < %s -loop-unswitch -S | FileCheck %s
+
+; In cases where two address spaces do not have the same size pointer, the
+; input for the addrspacecast should not be used as a substitute for itself
+; when manipulating the pointer.
+
+target datalayout = "e-m:e-p:16:16-p1:32:16-i32:16-i64:16-n8:16"
+
+define void @foo() {
+; CHECK-LABEL: @foo
+entry:
+  %arrayidx.i1 = getelementptr inbounds i16, i16* undef, i16 undef
+  %arrayidx.i = addrspacecast i16* %arrayidx.i1 to i16 addrspace(1)*
+  br i1 undef, label %for.body.i, label %bar.exit
+
+for.body.i:                                       ; preds = %for.body.i, %entry
+; When we call makeLoopInvariant (i.e. trivial LICM) on this load, it 
+; will try to find the base object to prove deferenceability.  If we look
+; through the addrspacecast, we'll fail an assertion about bitwidths matching
+; CHECK-LABEL: for.body.i
+; CHECK:   %0 = load i16, i16 addrspace(1)* %arrayidx.i, align 2
+  %0 = load i16, i16 addrspace(1)* %arrayidx.i, align 2
+  %cmp1.i = icmp eq i16 %0, 0
+  br i1 %cmp1.i, label %bar.exit, label %for.body.i
+
+bar.exit:                                         ; preds = %for.body.i, %entry
+  ret void
+}




More information about the llvm-commits mailing list