[llvm] 419c694 - [SimplifyLibCalls] Remove over-eager early return in strlen optzns.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 27 07:20:20 PDT 2020
Author: Florian Hahn
Date: 2020-08-27T15:19:45+01:00
New Revision: 419c6948df420dc2638e74a2b409e1d117256050
URL: https://github.com/llvm/llvm-project/commit/419c6948df420dc2638e74a2b409e1d117256050
DIFF: https://github.com/llvm/llvm-project/commit/419c6948df420dc2638e74a2b409e1d117256050.diff
LOG: [SimplifyLibCalls] Remove over-eager early return in strlen optzns.
Currently we bail out early for strlen calls with a GEP operand, if none
of the GEP specific optimizations fire. But there could be later
optimizations that still apply, which we currently miss out on.
An example is that we do not apply the following optimization
strlen(x) == 0 --> *x == 0
Unless I am missing something, there seems to be no reason for bailing
out early there.
Fixes PR47149.
Reviewed By: lebedev.ri, xbolva00
Differential Revision: https://reviews.llvm.org/D85886
Added:
Modified:
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/test/Transforms/InstCombine/strlen-1.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 78a52c992e9f..34eb9e1b8124 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -693,8 +693,6 @@ Value *LibCallSimplifier::optimizeStringLength(CallInst *CI, IRBuilderBase &B,
Offset);
}
}
-
- return nullptr;
}
// strlen(x?"foo":"bars") --> x ? 3 : 4
diff --git a/llvm/test/Transforms/InstCombine/strlen-1.ll b/llvm/test/Transforms/InstCombine/strlen-1.ll
index e9a6e714acd0..61bc2e57b08d 100644
--- a/llvm/test/Transforms/InstCombine/strlen-1.ll
+++ b/llvm/test/Transforms/InstCombine/strlen-1.ll
@@ -223,9 +223,7 @@ define i32 @test2(i8* %str) #0 {
define i1 @strlen0_after_write_to_first_byte_global() {
; CHECK-LABEL: @strlen0_after_write_to_first_byte_global(
; CHECK-NEXT: store i8 49, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @a, i32 0, i32 0), align 16
-; CHECK-NEXT: [[LEN:%.*]] = tail call i32 @strlen(i8* nonnull dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @a, i32 0, i32 0))
-; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[LEN]], 0
-; CHECK-NEXT: ret i1 [[CMP]]
+; CHECK-NEXT: ret i1 false
;
store i8 49, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @a, i64 0, i64 0), align 16
%len = tail call i32 @strlen(i8* nonnull dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @a, i64 0, i64 0))
@@ -236,8 +234,8 @@ define i1 @strlen0_after_write_to_first_byte_global() {
define i1 @strlen0_after_write_to_second_byte_global() {
; CHECK-LABEL: @strlen0_after_write_to_second_byte_global(
; CHECK-NEXT: store i8 49, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @a, i32 0, i32 1), align 16
-; CHECK-NEXT: [[LEN:%.*]] = tail call i32 @strlen(i8* nonnull dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @a, i32 0, i32 0))
-; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[LEN]], 0
+; CHECK-NEXT: [[STRLENFIRST:%.*]] = load i8, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @a, i32 0, i32 0), align 1
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[STRLENFIRST]], 0
; CHECK-NEXT: ret i1 [[CMP]]
;
store i8 49, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @a, i64 0, i64 1), align 16
More information about the llvm-commits
mailing list