From 154609b1dfa6882b490a2652291548cf457f2e3b Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 11 Apr 2022 16:45:27 +0200 Subject: [PATCH] [InstCombine] Add strlen of gep test without inbounds (NFC) --- llvm/test/Transforms/InstCombine/strlen-1.ll | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/llvm/test/Transforms/InstCombine/strlen-1.ll b/llvm/test/Transforms/InstCombine/strlen-1.ll index ea6079d..0cfdc75 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 -- 2.7.4