diff options
author | Nikita Popov <npopov@redhat.com> | 2023-12-08 15:40:32 +0100 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2023-12-08 15:45:58 +0100 |
commit | 4a2a6397f11da7c15a73d19fb1e6c9dcd1ceb5af (patch) | |
tree | 332b42db22e1eaeff717e0e3889e1335076492cd | |
parent | cf029a22bd0c87bb475ee0440e9085bb96c7e011 (diff) | |
download | llvm-4a2a6397f11da7c15a73d19fb1e6c9dcd1ceb5af.zip llvm-4a2a6397f11da7c15a73d19fb1e6c9dcd1ceb5af.tar.gz llvm-4a2a6397f11da7c15a73d19fb1e6c9dcd1ceb5af.tar.bz2 |
[InstCombine] Relax one-use check for icmp of gep fold
Instead of checking whether the GEP as a whole is constant, only
check whether it has constant incides. This matches what we do in
other places in this code.
This has little practical impact, because it is mostly already
handled through other cases anyway. We see a difference for
non-inbounds equality comparisons.
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 4 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/icmp-gep.ll | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index b1c7039..e42e011 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -812,8 +812,8 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS, // Only lower this if the icmp is the only user of the GEP or if we expect // the result to fold to a constant! if ((GEPsInBounds || CmpInst::isEquality(Cond)) && - (isa<ConstantExpr>(GEPLHS) || GEPLHS->hasOneUse()) && - (isa<ConstantExpr>(GEPRHS) || GEPRHS->hasOneUse())) { + (GEPLHS->hasAllConstantIndices() || GEPLHS->hasOneUse()) && + (GEPRHS->hasAllConstantIndices() || GEPRHS->hasOneUse())) { // ((gep Ptr, OFFSET1) cmp (gep Ptr, OFFSET2) ---> (OFFSET1 cmp OFFSET2) Value *L = EmitGEPOffset(GEPLHS); Value *R = EmitGEPOffset(GEPRHS); diff --git a/llvm/test/Transforms/InstCombine/icmp-gep.ll b/llvm/test/Transforms/InstCombine/icmp-gep.ll index da5976f..99c784d 100644 --- a/llvm/test/Transforms/InstCombine/icmp-gep.ll +++ b/llvm/test/Transforms/InstCombine/icmp-gep.ll @@ -431,9 +431,9 @@ define i1 @test60_extra_use_const_operands_inbounds(ptr %foo, i64 %i, i64 %j) { define i1 @test60_extra_use_const_operands_no_inbounds(ptr %foo, i64 %i, i64 %j) { ; CHECK-LABEL: @test60_extra_use_const_operands_no_inbounds( ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i32, ptr [[FOO:%.*]], i64 1 -; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i16, ptr [[FOO]], i64 [[J:%.*]] ; CHECK-NEXT: call void @use(ptr [[GEP1]]) -; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[GEP1]], [[GEP2]] +; CHECK-NEXT: [[GEP2_IDX_MASK:%.*]] = and i64 [[J:%.*]], 9223372036854775807 +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[GEP2_IDX_MASK]], 2 ; CHECK-NEXT: ret i1 [[CMP]] ; %gep1 = getelementptr i32, ptr %foo, i64 1 |