From c720fad16fd90d625a1373d562e568cd36770fd1 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 30 Sep 2022 13:06:53 +0200 Subject: [PATCH] [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. --- .../Transforms/InstCombine/phi-select-constant.ll | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/phi-select-constant.ll b/llvm/test/Transforms/InstCombine/phi-select-constant.ll index 62183b0..5a78c24 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 +} -- 2.7.4