[llvm] cf029a2 - [InstCombine] Add some more multi-use icmp gep folding tests (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 8 06:46:06 PST 2023


Author: Nikita Popov
Date: 2023-12-08T15:45:58+01:00
New Revision: cf029a22bd0c87bb475ee0440e9085bb96c7e011

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

LOG: [InstCombine] Add some more multi-use icmp gep folding tests (NFC)

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/icmp-gep.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/icmp-gep.ll b/llvm/test/Transforms/InstCombine/icmp-gep.ll
index 7d266b7b246ae0..da5976f9653ae0 100644
--- a/llvm/test/Transforms/InstCombine/icmp-gep.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-gep.ll
@@ -397,6 +397,52 @@ define i1 @test61_as1(ptr addrspace(1) %foo, i16 %i, i16 %j) {
 ; Don't transform non-inbounds GEPs.
 }
 
+define i1 @test60_extra_use(ptr %foo, i64 %i, i64 %j) {
+; CHECK-LABEL: @test60_extra_use(
+; CHECK-NEXT:    [[GEP1:%.*]] = getelementptr inbounds i32, ptr [[FOO:%.*]], i64 [[I:%.*]]
+; CHECK-NEXT:    [[GEP2:%.*]] = getelementptr inbounds i16, ptr [[FOO]], i64 [[J:%.*]]
+; CHECK-NEXT:    call void @use(ptr [[GEP1]])
+; CHECK-NEXT:    call void @use(ptr [[GEP2]])
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult ptr [[GEP1]], [[GEP2]]
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %gep1 = getelementptr inbounds i32, ptr %foo, i64 %i
+  %gep2 = getelementptr inbounds i16, ptr %foo, i64 %j
+  call void @use(ptr %gep1)
+  call void @use(ptr %gep2)
+  %cmp = icmp ult ptr %gep1, %gep2
+  ret i1 %cmp
+}
+
+define i1 @test60_extra_use_const_operands_inbounds(ptr %foo, i64 %i, i64 %j) {
+; CHECK-LABEL: @test60_extra_use_const_operands_inbounds(
+; CHECK-NEXT:    [[GEP1:%.*]] = getelementptr inbounds i32, ptr [[FOO:%.*]], i64 1
+; CHECK-NEXT:    call void @use(ptr nonnull [[GEP1]])
+; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i64 [[J:%.*]], 2
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %gep1 = getelementptr inbounds i32, ptr %foo, i64 1
+  %gep2 = getelementptr inbounds i16, ptr %foo, i64 %j
+  call void @use(ptr %gep1)
+  %cmp = icmp eq ptr %gep1, %gep2
+  ret i1 %cmp
+}
+
+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:    ret i1 [[CMP]]
+;
+  %gep1 = getelementptr i32, ptr %foo, i64 1
+  %gep2 = getelementptr i16, ptr %foo, i64 %j
+  call void @use(ptr %gep1)
+  %cmp = icmp eq ptr %gep1, %gep2
+  ret i1 %cmp
+}
+
 define i1 @test_scalable_same(ptr %x) {
 ; CHECK-LABEL: @test_scalable_same(
 ; CHECK-NEXT:    ret i1 false


        


More information about the llvm-commits mailing list