[llvm] 2c8362b - [NFC] Add pre-commit test for simplifyCastInst in PHITransAddr
Sergey Kachkov via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 7 01:43:35 PST 2023
Author: Sergey Kachkov
Date: 2023-02-07T12:43:19+03:00
New Revision: 2c8362b2a220b5854bdcfab13c8f6d87b9c78cb0
URL: https://github.com/llvm/llvm-project/commit/2c8362b2a220b5854bdcfab13c8f6d87b9c78cb0
DIFF: https://github.com/llvm/llvm-project/commit/2c8362b2a220b5854bdcfab13c8f6d87b9c78cb0.diff
LOG: [NFC] Add pre-commit test for simplifyCastInst in PHITransAddr
Added:
Modified:
llvm/test/Transforms/GVN/PRE/phi-translate-2.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/GVN/PRE/phi-translate-2.ll b/llvm/test/Transforms/GVN/PRE/phi-translate-2.ll
index 92dc991ed37c7..d968716d42873 100644
--- a/llvm/test/Transforms/GVN/PRE/phi-translate-2.ll
+++ b/llvm/test/Transforms/GVN/PRE/phi-translate-2.ll
@@ -300,3 +300,40 @@ if.end:
while.end:
ret void
}
+
+; Load from arrayidx2 is partially redundant, check that address translation can
+; fold sext + trunc across phi node together.
+define i32 @test7(ptr noalias %ptr1, ptr noalias %ptr2, i32 %i, i1 %cond) {
+; CHECK-LABEL: @test7(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
+; CHECK: if.then:
+; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[PTR1:%.*]], i32 [[I:%.*]]
+; CHECK-NEXT: [[TMP:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
+; CHECK-NEXT: store i32 [[TMP]], ptr [[PTR2:%.*]], align 4
+; CHECK-NEXT: [[IDX_EXT:%.*]] = sext i32 [[I]] to i64
+; CHECK-NEXT: br label [[IF_END]]
+; CHECK: if.end:
+; CHECK-NEXT: [[IDX:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[IDX_EXT]], [[IF_THEN]] ]
+; CHECK-NEXT: [[IDX_TRUNC:%.*]] = trunc i64 [[IDX]] to i32
+; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, ptr [[PTR1]], i32 [[IDX_TRUNC]]
+; CHECK-NEXT: [[RES:%.*]] = load i32, ptr [[ARRAYIDX2]], align 4
+; CHECK-NEXT: ret i32 [[RES]]
+;
+entry:
+ br i1 %cond, label %if.then, label %if.end
+
+if.then:
+ %arrayidx = getelementptr inbounds i32, ptr %ptr1, i32 %i
+ %tmp = load i32, ptr %arrayidx, align 4
+ store i32 %tmp, ptr %ptr2, align 4
+ %idx.ext = sext i32 %i to i64
+ br label %if.end
+
+if.end:
+ %idx = phi i64 [ 0, %entry ], [ %idx.ext, %if.then ]
+ %idx.trunc = trunc i64 %idx to i32
+ %arrayidx2 = getelementptr inbounds i32, ptr %ptr1, i32 %idx.trunc
+ %res = load i32, ptr %arrayidx2, align 4
+ ret i32 %res
+}
More information about the llvm-commits
mailing list