[PATCH] llvm.noalias - GetStringLength should look through them too

hfinkel at anl.gov hfinkel at anl.gov
Thu Apr 30 09:05:04 PDT 2015


Hi chandlerc, reames,

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

http://reviews.llvm.org/D9392

Files:
  lib/Analysis/ValueTracking.cpp
  test/Transforms/InstCombine/strlen-1.ll

Index: lib/Analysis/ValueTracking.cpp
===================================================================
--- lib/Analysis/ValueTracking.cpp
+++ lib/Analysis/ValueTracking.cpp
@@ -2599,7 +2599,7 @@
   assert(V);
 
   // Look through bitcast instructions and geps.
-  V = V->stripPointerCasts();
+  V = V->stripPointerCasts(/*LookThroughNoAlias*/true);
 
   // If the value is a GEP instruction or constant expression, treat it as an
   // offset.
@@ -2682,7 +2682,7 @@
 /// the specified pointer, return 'len+1'.  If we can't, return 0.
 static uint64_t GetStringLengthH(Value *V, SmallPtrSetImpl<PHINode*> &PHIs) {
   // Look through noop bitcast instructions.
-  V = V->stripPointerCasts();
+  V = V->stripPointerCasts(/*LookThroughNoAlias*/true);
 
   // If this is a PHI node, there are two cases: either we have already seen it
   // or we haven't.
Index: test/Transforms/InstCombine/strlen-1.ll
===================================================================
--- test/Transforms/InstCombine/strlen-1.ll
+++ test/Transforms/InstCombine/strlen-1.ll
@@ -23,6 +23,15 @@
 ; CHECK-NEXT: ret i32 5
 }
 
+define i32 @test_simplify1a() {
+; CHECK-LABEL: @test_simplify1a(
+  %hello_p = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0
+  %hello_pa = call i8* @llvm.noalias.p0i8(i8* %hello_p, metadata !1)
+  %hello_l = call i32 @strlen(i8* %hello_pa)
+  ret i32 %hello_l
+; CHECK-NEXT: ret i32 5
+}
+
 define i32 @test_simplify2() {
 ; CHECK-LABEL: @test_simplify2(
   %null_p = getelementptr [1 x i8], [1 x i8]* @null, i32 0, i32 0
@@ -107,3 +116,9 @@
   ret i32 %a_l
 ; CHECK-NEXT: ret i32 %a_l
 }
+
+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: D9392.24730.patch
Type: text/x-patch
Size: 1728 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150430/6c85fd2d/attachment.bin>


More information about the llvm-commits mailing list