[llvm] ecf5813 - [InstCombine] Add select(cond,gep(gep(x,y),z),gep(x,y)) tests from PR51069
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 15 11:30:16 PDT 2021
Author: Simon Pilgrim
Date: 2021-07-15T19:26:24+01:00
New Revision: ecf5813c824cee2e332a2a625ff88d55c8e51b29
URL: https://github.com/llvm/llvm-project/commit/ecf5813c824cee2e332a2a625ff88d55c8e51b29
DIFF: https://github.com/llvm/llvm-project/commit/ecf5813c824cee2e332a2a625ff88d55c8e51b29.diff
LOG: [InstCombine] Add select(cond,gep(gep(x,y),z),gep(x,y)) tests from PR51069
Added:
Modified:
llvm/test/Transforms/InstCombine/select-gep.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/select-gep.ll b/llvm/test/Transforms/InstCombine/select-gep.ll
index 8f96f49b761a..e2223aa428ce 100644
--- a/llvm/test/Transforms/InstCombine/select-gep.ll
+++ b/llvm/test/Transforms/InstCombine/select-gep.ll
@@ -99,6 +99,38 @@ define i32* @test2b(i32* %p, i64 %x, i64 %y) {
ret i32* %select
}
+; PR51069
+define i32* @test2c(i32* %p, i64 %x, i64 %y) {
+; CHECK-LABEL: @test2c(
+; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i32, i32* [[P:%.*]], i64 [[X:%.*]]
+; CHECK-NEXT: [[ICMP:%.*]] = icmp ugt i64 [[X]], [[Y:%.*]]
+; CHECK-NEXT: [[SEL_IDX:%.*]] = select i1 [[ICMP]], i64 0, i64 6
+; CHECK-NEXT: [[SEL:%.*]] = getelementptr i32, i32* [[GEP1]], i64 [[SEL_IDX]]
+; CHECK-NEXT: ret i32* [[SEL]]
+;
+ %gep1 = getelementptr inbounds i32, i32* %p, i64 %x
+ %gep2 = getelementptr inbounds i32, i32* %gep1, i64 6
+ %icmp = icmp ugt i64 %x, %y
+ %sel = select i1 %icmp, i32* %gep1, i32* %gep2
+ ret i32* %sel
+}
+
+; PR51069
+define i32* @test2d(i32* %p, i64 %x, i64 %y) {
+; CHECK-LABEL: @test2d(
+; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i32, i32* [[P:%.*]], i64 [[X:%.*]]
+; CHECK-NEXT: [[ICMP:%.*]] = icmp ugt i64 [[X]], [[Y:%.*]]
+; CHECK-NEXT: [[SEL_IDX:%.*]] = select i1 [[ICMP]], i64 6, i64 0
+; CHECK-NEXT: [[SEL:%.*]] = getelementptr i32, i32* [[GEP1]], i64 [[SEL_IDX]]
+; CHECK-NEXT: ret i32* [[SEL]]
+;
+ %gep1 = getelementptr inbounds i32, i32* %p, i64 %x
+ %gep2 = getelementptr inbounds i32, i32* %gep1, i64 6
+ %icmp = icmp ugt i64 %x, %y
+ %sel = select i1 %icmp, i32* %gep2, i32* %gep1
+ ret i32* %sel
+}
+
; Three (or more) operand GEPs are currently expected to not be optimised,
; though they could be in principle.
More information about the llvm-commits
mailing list