<div dir="ltr">LGTM.<div><br></div><div>-Eli</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Sep 27, 2013 at 3:48 PM, Matt Arsenault <span dir="ltr"><<a href="mailto:Matthew.Arsenault@amd.com" target="_blank">Matthew.Arsenault@amd.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The test's output doesn't change, but this ensures this is actually hit with a different address space.<br>
<br>
<a href="http://llvm-reviews.chandlerc.com/D1778" target="_blank">http://llvm-reviews.chandlerc.com/D1778</a><br>
<br>
Files:<br>
  lib/Transforms/InstCombine/InstCombineCompares.cpp<br>
  test/Transforms/InstCombine/load-cmp.ll<br>
<br>
Index: lib/Transforms/InstCombine/InstCombineCompares.cpp<br>
===================================================================<br>
--- lib/Transforms/InstCombine/InstCombineCompares.cpp<br>
+++ lib/Transforms/InstCombine/InstCombineCompares.cpp<br>
@@ -394,9 +394,12 @@<br>
   // If the index is larger than the pointer size of the target, truncate the<br>
   // index down like the GEP would do implicitly.  We don't have to do this for<br>
   // an inbounds GEP because the index can't be out of range.<br>
-  if (!GEP->isInBounds() &&<br>
-      Idx->getType()->getPrimitiveSizeInBits() > TD->getPointerSizeInBits())<br>
-    Idx = Builder->CreateTrunc(Idx, TD->getIntPtrType(Idx->getContext()));<br>
+  if (!GEP->isInBounds()) {<br>
+    Type *IntPtrTy = TD->getIntPtrType(GEP->getType());<br>
+    unsigned PtrSize = IntPtrTy->getIntegerBitWidth();<br>
+    if (Idx->getType()->getPrimitiveSizeInBits() > PtrSize)<br>
+      Idx = Builder->CreateTrunc(Idx, IntPtrTy);<br>
+  }<br>
<br>
   // If the comparison is only true for one or two elements, emit direct<br>
   // comparisons.<br>
Index: test/Transforms/InstCombine/load-cmp.ll<br>
===================================================================<br>
--- test/Transforms/InstCombine/load-cmp.ll<br>
+++ test/Transforms/InstCombine/load-cmp.ll<br>
@@ -1,8 +1,12 @@<br>
 ; RUN: opt -instcombine -S < %s | FileCheck -check-prefix=NODL %s<br>
-; RUN: opt -instcombine -S -default-data-layout="p:32:32:32-n8:16:32:64" < %s | FileCheck -check-prefix=P32 %s<br>
+; RUN: opt -instcombine -S -default-data-layout="p:32:32:32-p1:16:16:16-n8:16:32:64" < %s | FileCheck -check-prefix=P32 %s<br>
<br>
 @G16 = internal constant [10 x i16] [i16 35, i16 82, i16 69, i16 81, i16 85,<br>
                                      i16 73, i16 82, i16 69, i16 68, i16 0]<br>
+<br>
+@G16_as1 = internal addrspace(1) constant [10 x i16] [i16 35, i16 82, i16 69, i16 81, i16 85,<br>
+                                                      i16 73, i16 82, i16 69, i16 68, i16 0]<br>
+<br>
 @GD = internal constant [6 x double]<br>
    [double -10.0, double 1.0, double 4.0, double 2.0, double -20.0, double -40.0]<br>
<br>
@@ -56,6 +60,18 @@<br>
 ; P32-NEXT: ret i1 %R<br>
 }<br>
<br>
+define i1 @test1_noinbounds_as1(i32 %x) {<br>
+  %p = getelementptr [10 x i16] addrspace(1)* @G16_as1, i16 0, i32 %x<br>
+  %q = load i16 addrspace(1)* %p<br>
+  %r = icmp eq i16 %q, 0<br>
+  ret i1 %r<br>
+<br>
+; P32-LABEL: @test1_noinbounds_as1(<br>
+; P32-NEXT: trunc i32 %x to i16<br>
+; P32-NEXT: %r = icmp eq i16 %1, 9<br>
+; P32-NEXT: ret i1 %r<br>
+}<br>
+<br>
 define i1 @test2(i32 %X) {<br>
   %P = getelementptr inbounds [10 x i16]* @G16, i32 0, i32 %X<br>
   %Q = load i16* %P<br>
<br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div>