[llvm] c720fad - [InstCombine] Add test for phi translation during select of phi fold (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 30 04:08:10 PDT 2022
Author: Nikita Popov
Date: 2022-09-30T13:07:58+02:00
New Revision: c720fad16fd90d625a1373d562e568cd36770fd1
URL: https://github.com/llvm/llvm-project/commit/c720fad16fd90d625a1373d562e568cd36770fd1
DIFF: https://github.com/llvm/llvm-project/commit/c720fad16fd90d625a1373d562e568cd36770fd1.diff
LOG: [InstCombine] Add test for phi translation during select of phi fold (NFC)
The phi translation performed during this fold is important for
correctness, but was apparently untested.
Added:
Modified:
llvm/test/Transforms/InstCombine/phi-select-constant.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/phi-select-constant.ll b/llvm/test/Transforms/InstCombine/phi-select-constant.ll
index 62183b028088..5a78c24c2f42 100644
--- a/llvm/test/Transforms/InstCombine/phi-select-constant.ll
+++ b/llvm/test/Transforms/InstCombine/phi-select-constant.ll
@@ -158,3 +158,40 @@ inf_loop:
unreachable: ; No predecessors!
ret i16 %s
}
+
+define i32 @phi_trans(i1 %c, i1 %c2, i32 %v) {
+; CHECK-LABEL: @phi_trans(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[ELSE:%.*]]
+; CHECK: if:
+; CHECK-NEXT: [[V2:%.*]] = add i32 [[V:%.*]], 1
+; CHECK-NEXT: br label [[JOIN:%.*]]
+; CHECK: else:
+; CHECK-NEXT: [[V3:%.*]] = mul i32 [[V]], 3
+; CHECK-NEXT: [[V5:%.*]] = lshr i32 [[V]], 1
+; CHECK-NEXT: [[PHI_SEL:%.*]] = select i1 [[C2:%.*]], i32 [[V3]], i32 [[V5]]
+; CHECK-NEXT: br label [[JOIN]]
+; CHECK: join:
+; CHECK-NEXT: [[PHI1:%.*]] = phi i32 [ [[V2]], [[IF]] ], [ [[PHI_SEL]], [[ELSE]] ]
+; CHECK-NEXT: ret i32 [[PHI1]]
+;
+entry:
+ br i1 %c, label %if, label %else
+
+if:
+ %v2 = add i32 %v, 1
+ %v4 = shl i32 %v, 1
+ br label %join
+
+else:
+ %v3 = mul i32 %v, 3
+ %v5 = lshr i32 %v, 1
+ br label %join
+
+join:
+ %phi1 = phi i1 [ true, %if ], [ %c2, %else ]
+ %phi2 = phi i32 [ %v2, %if ], [ %v3, %else ]
+ %phi3 = phi i32 [ %v4, %if ], [ %v5, %else ]
+ %sel = select i1 %phi1, i32 %phi2, i32 %phi3
+ ret i32 %sel
+}
More information about the llvm-commits
mailing list