[PATCH] llvm.noalias - InstCombiner::FoldGEPICmp should look through them

hfinkel at anl.gov hfinkel at anl.gov
Thu Apr 30 09:08:18 PDT 2015


Hi chandlerc, reames,

This is part of the series started by D9375, and teaches  InstCombiner::FoldGEPICmp to look through calls to llvm.noalias.

http://reviews.llvm.org/D9394

Files:
  lib/Transforms/InstCombine/InstCombineCompares.cpp
  test/Transforms/InstCombine/icmp.ll

Index: lib/Transforms/InstCombine/InstCombineCompares.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -618,7 +618,7 @@
   // Look through bitcasts and addrspacecasts. We do not however want to remove
   // 0 GEPs.
   if (!isa<GetElementPtrInst>(RHS))
-    RHS = RHS->stripPointerCasts();
+    RHS = RHS->stripPointerCasts(/*LookThroughNoAlias*/true);
 
   Value *PtrBase = GEPLHS->getOperand(0);
   if (PtrBase == RHS && GEPLHS->isInBounds()) {
@@ -657,8 +657,8 @@
       if (GEPLHS->isInBounds() && GEPRHS->isInBounds() &&
           (GEPLHS->hasAllConstantIndices() || GEPLHS->hasOneUse()) &&
           (GEPRHS->hasAllConstantIndices() || GEPRHS->hasOneUse()) &&
-          PtrBase->stripPointerCasts() ==
-              GEPRHS->getOperand(0)->stripPointerCasts()) {
+          PtrBase->stripPointerCasts(/*LookThroughNoAlias*/true) ==
+              GEPRHS->getOperand(0)->stripPointerCasts(true)) {
         Value *LOffset = EmitGEPOffset(GEPLHS);
         Value *ROffset = EmitGEPOffset(GEPRHS);
 
Index: test/Transforms/InstCombine/icmp.ll
===================================================================
--- test/Transforms/InstCombine/icmp.ll
+++ test/Transforms/InstCombine/icmp.ll
@@ -658,6 +658,20 @@
 ; CHECK-NEXT: ret i1
 }
 
+define i1 @test60a(i8* %foo, i64 %i, i64 %j) {
+  %bit = bitcast i8* %foo to i32*
+  %gep1 = getelementptr inbounds i32, i32* %bit, i64 %i
+  %fooa = call i8* @llvm.noalias.p0i8(i8* %foo, metadata !1)
+  %gep2 = getelementptr inbounds i8, i8* %fooa, i64 %j
+  %cast1 = bitcast i32* %gep1 to i8*
+  %cmp = icmp ult i8* %cast1, %gep2
+  ret i1 %cmp
+; CHECK-LABEL: @test60a(
+; CHECK-NEXT: %gep1.idx = shl nuw i64 %i, 2
+; CHECK-NEXT: icmp slt i64 %gep1.idx, %j
+; CHECK-NEXT: ret i1
+}
+
 define i1 @test60_as1(i8 addrspace(1)* %foo, i64 %i, i64 %j) {
   %bit = bitcast i8 addrspace(1)* %foo to i32 addrspace(1)*
   %gep1 = getelementptr inbounds i32, i32 addrspace(1)* %bit, i64 %i
@@ -1603,3 +1617,9 @@
   %s = select i1 %cmp, i32 10000, i32 0
   ret i32 %s
 }
+
+declare i8* @llvm.noalias.p0i8(i8*, metadata) nounwind
+
+!0 = !{!0, !"some domain"}
+!1 = !{!1, !0, !"some scope"}
+

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9394.24732.patch
Type: text/x-patch
Size: 2264 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150430/9544ee87/attachment.bin>


More information about the llvm-commits mailing list