[PATCH] llvm.noalias - Pointer comparison folding should look through them

hfinkel at anl.gov hfinkel at anl.gov
Thu Apr 30 08:45:39 PDT 2015


Hi reames, chandlerc,

This is part of the series started by D9375, and makes sure that pointer comparison folding that look though calls to llvm.noalias.

http://reviews.llvm.org/D9387

Files:
  lib/Analysis/InstructionSimplify.cpp
  test/Transforms/InstSimplify/noalias.ll

Index: lib/Analysis/InstructionSimplify.cpp
===================================================================
--- lib/Analysis/InstructionSimplify.cpp
+++ lib/Analysis/InstructionSimplify.cpp
@@ -625,6 +625,12 @@
         break;
       V = GA->getAliasee();
     } else {
+      if (IntrinsicInst *I = dyn_cast<IntrinsicInst>(V))
+        if (I->getIntrinsicID() == Intrinsic::noalias) {
+          V = I->getOperand(0);
+          continue;
+        }
+
       break;
     }
     assert(V->getType()->getScalarType()->isPointerTy() &&
@@ -1949,8 +1955,8 @@
                                     CmpInst::Predicate Pred, Value *LHS,
                                     Value *RHS) {
   // First, skip past any trivial no-ops.
-  LHS = LHS->stripPointerCasts();
-  RHS = RHS->stripPointerCasts();
+  LHS = LHS->stripPointerCasts(/*LookThroughNoAlias*/true);
+  RHS = RHS->stripPointerCasts(/*LookThroughNoAlias*/true);
 
   // A non-null pointer is not equal to a null pointer.
   if (llvm::isKnownNonNull(LHS, TLI) && isa<ConstantPointerNull>(RHS) &&
Index: test/Transforms/InstSimplify/noalias.ll
===================================================================
--- test/Transforms/InstSimplify/noalias.ll
+++ test/Transforms/InstSimplify/noalias.ll
@@ -18,7 +18,33 @@
 ; CHECK: ret i8* undef
 }
 
+define i1 @bitcast() {
+; CHECK-LABEL: @bitcast(
+  %a = alloca i32
+  %b = alloca i64
+  %x = bitcast i32* %a to i8*
+  %z = bitcast i64* %b to i8*
+  %y = call i8* @llvm.noalias.p0i8(i8* %z, metadata !1)
+  %cmp = icmp eq i8* %x, %y
+  ret i1 %cmp
+; CHECK-NEXT: ret i1 false
+}
+
+%gept = type { i32, i32 }
+
+define i1 @gep3() {
+; CHECK-LABEL: @gep3(
+  %x = alloca %gept, align 8
+  %a = getelementptr %gept, %gept* %x, i64 0, i32 0
+  %y = call %gept* @llvm.noalias.p0gept(%gept* %x, metadata !1)
+  %b = getelementptr %gept, %gept* %y, i64 0, i32 1
+  %equal = icmp eq i32* %a, %b
+  ret i1 %equal
+; CHECK-NEXT: ret i1 false
+}
+
 declare i8* @llvm.noalias.p0i8(i8*, metadata) nounwind
+declare %gept* @llvm.noalias.p0gept(%gept*, 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: D9387.24721.patch
Type: text/x-patch
Size: 2125 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150430/e27e392f/attachment.bin>


More information about the llvm-commits mailing list