forked from OSchip/llvm-project
[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
This commit is contained in:
parent
5b2b754565
commit
419c6948df
|
@ -693,8 +693,6 @@ Value *LibCallSimplifier::optimizeStringLength(CallInst *CI, IRBuilderBase &B,
|
|||
Offset);
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// strlen(x?"foo":"bars") --> x ? 3 : 4
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue