[llvm] 154609b - [InstCombine] Add strlen of gep test without inbounds (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 11 07:51:16 PDT 2022


Author: Nikita Popov
Date: 2022-04-11T16:51:09+02:00
New Revision: 154609b1dfa6882b490a2652291548cf457f2e3b

URL: https://github.com/llvm/llvm-project/commit/154609b1dfa6882b490a2652291548cf457f2e3b
DIFF: https://github.com/llvm/llvm-project/commit/154609b1dfa6882b490a2652291548cf457f2e3b.diff

LOG: [InstCombine] Add strlen of gep test without inbounds (NFC)

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/strlen-1.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/strlen-1.ll b/llvm/test/Transforms/InstCombine/strlen-1.ll
index ea6079d597196..0cfdc75269e3c 100644
--- a/llvm/test/Transforms/InstCombine/strlen-1.ll
+++ b/llvm/test/Transforms/InstCombine/strlen-1.ll
@@ -113,8 +113,8 @@ define i32 @test_simplify9(i1 %x) {
 ; Check the case that should be simplified to a sub instruction.
 ; strlen(@hello + x) --> 5 - x
 
-define i32 @test_simplify10(i32 %x) {
-; CHECK-LABEL: @test_simplify10(
+define i32 @test_simplify10_inbounds(i32 %x) {
+; CHECK-LABEL: @test_simplify10_inbounds(
 ; CHECK-NEXT:    [[TMP1:%.*]] = sub i32 5, [[X:%.*]]
 ; CHECK-NEXT:    ret i32 [[TMP1]]
 ;
@@ -123,6 +123,17 @@ define i32 @test_simplify10(i32 %x) {
   ret i32 %hello_l
 }
 
+define i32 @test_simplify10_no_inbounds(i32 %x) {
+; CHECK-LABEL: @test_simplify10_no_inbounds(
+; CHECK-NEXT:    [[HELLO_P:%.*]] = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 [[X:%.*]]
+; CHECK-NEXT:    [[HELLO_L:%.*]] = call i32 @strlen(i8* noundef nonnull dereferenceable(1) [[HELLO_P]])
+; CHECK-NEXT:    ret i32 [[HELLO_L]]
+;
+  %hello_p = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 %x
+  %hello_l = call i32 @strlen(i8* %hello_p)
+  ret i32 %hello_l
+}
+
 ; strlen(@null_hello_mid + (x & 7)) --> 9 - (x & 7)
 
 define i32 @test_simplify11(i32 %x) {
@@ -203,7 +214,7 @@ define i32 @test_no_simplify3_on_null_opt(i32 %x) #0 {
 
 define i32 @test1(i8* %str) {
 ; CHECK-LABEL: @test1(
-; CHECK-NEXT:    [[LEN:%.*]] = tail call i32 @strlen(i8* noundef nonnull dereferenceable(1) [[STR:%.*]]) [[ATTR1:#.*]]
+; CHECK-NEXT:    [[LEN:%.*]] = tail call i32 @strlen(i8* noundef nonnull dereferenceable(1) [[STR:%.*]]) #[[ATTR1:[0-9]+]]
 ; CHECK-NEXT:    ret i32 [[LEN]]
 ;
   %len = tail call i32 @strlen(i8* %str) nounwind
@@ -212,7 +223,7 @@ define i32 @test1(i8* %str) {
 
 define i32 @test2(i8* %str) #0 {
 ; CHECK-LABEL: @test2(
-; CHECK-NEXT:    [[LEN:%.*]] = tail call i32 @strlen(i8* noundef [[STR:%.*]]) [[ATTR1]]
+; CHECK-NEXT:    [[LEN:%.*]] = tail call i32 @strlen(i8* noundef [[STR:%.*]]) #[[ATTR1]]
 ; CHECK-NEXT:    ret i32 [[LEN]]
 ;
   %len = tail call i32 @strlen(i8* %str) nounwind


        


More information about the llvm-commits mailing list