From 4549a8d251cfa91cc6230139595f0b7efdf199d9 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 26 Aug 2024 12:01:27 +0200 Subject: [PATCH] [InstCombine] Add additional tests for select of phi transform (NFC) Test coverage for the canSelectOperandBeMappingIntoPredBlock() logic. --- .../InstCombine/phi-select-constant.ll | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/phi-select-constant.ll b/llvm/test/Transforms/InstCombine/phi-select-constant.ll index dbe61c42eec6f8..9d61891127690c 100644 --- a/llvm/test/Transforms/InstCombine/phi-select-constant.ll +++ b/llvm/test/Transforms/InstCombine/phi-select-constant.ll @@ -195,3 +195,89 @@ join: %sel = select i1 %phi1, i32 %phi2, i32 %phi3 ret i32 %sel } + +define i32 @dominating_values_select_same_block(i1 %c1, i1 %c2, ptr %p, ptr %p2) { +; CHECK-LABEL: @dominating_values_select_same_block( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[B:%.*]] = load i32, ptr [[P2:%.*]], align 4 +; CHECK-NEXT: br i1 [[C1:%.*]], label [[FINAL:%.*]], label [[DELAY:%.*]] +; CHECK: delay: +; CHECK-NEXT: [[A:%.*]] = load i32, ptr [[P:%.*]], align 4 +; CHECK-NEXT: [[TMP0:%.*]] = select i1 [[C2:%.*]], i32 [[A]], i32 [[B]] +; CHECK-NEXT: br label [[FINAL]] +; CHECK: final: +; CHECK-NEXT: [[USE2:%.*]] = phi i32 [ [[B]], [[ENTRY:%.*]] ], [ [[TMP0]], [[DELAY]] ] +; CHECK-NEXT: ret i32 [[USE2]] +; +entry: + %a = load i32, ptr %p + %b = load i32, ptr %p2 + br i1 %c1, label %final, label %delay + +delay: + br label %final + +final: + %use2 = phi i1 [ false, %entry ], [ %c2, %delay ] + %value = select i1 %use2, i32 %a, i32 %b + ret i32 %value +} + +define i32 @dominating_values_select_not_same_block(i1 %c1, i1 %c2, ptr %p, ptr %p2) { +; CHECK-LABEL: @dominating_values_select_not_same_block( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[A:%.*]] = load i32, ptr [[P:%.*]], align 4 +; CHECK-NEXT: [[B:%.*]] = load i32, ptr [[P2:%.*]], align 4 +; CHECK-NEXT: br i1 [[C1:%.*]], label [[FINAL:%.*]], label [[DELAY:%.*]] +; CHECK: delay: +; CHECK-NEXT: br label [[FINAL]] +; CHECK: final: +; CHECK-NEXT: [[USE2:%.*]] = phi i1 [ false, [[ENTRY:%.*]] ], [ [[C2:%.*]], [[DELAY]] ] +; CHECK-NEXT: br label [[SPLIT:%.*]] +; CHECK: split: +; CHECK-NEXT: [[VALUE:%.*]] = select i1 [[USE2]], i32 [[A]], i32 [[B]] +; CHECK-NEXT: ret i32 [[VALUE]] +; +entry: + %a = load i32, ptr %p + %b = load i32, ptr %p2 + br i1 %c1, label %final, label %delay + +delay: + br label %final + +final: + %use2 = phi i1 [ false, %entry ], [ %c2, %delay ] + br label %split + +split: + %value = select i1 %use2, i32 %a, i32 %b + ret i32 %value +} + +define i32 @not_dominating_values(i1 %c1, i1 %c2, ptr %p, ptr %p2) { +; CHECK-LABEL: @not_dominating_values( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[A:%.*]] = load i32, ptr [[P:%.*]], align 4 +; CHECK-NEXT: br i1 [[C1:%.*]], label [[FINAL:%.*]], label [[DELAY:%.*]] +; CHECK: delay: +; CHECK-NEXT: br label [[FINAL]] +; CHECK: final: +; CHECK-NEXT: [[USE2:%.*]] = phi i1 [ false, [[ENTRY:%.*]] ], [ [[C2:%.*]], [[DELAY]] ] +; CHECK-NEXT: [[B:%.*]] = load i32, ptr [[P2:%.*]], align 4 +; CHECK-NEXT: [[VALUE:%.*]] = select i1 [[USE2]], i32 [[A]], i32 [[B]] +; CHECK-NEXT: ret i32 [[VALUE]] +; +entry: + %a = load i32, ptr %p + br i1 %c1, label %final, label %delay + +delay: + br label %final + +final: + %use2 = phi i1 [ false, %entry ], [ %c2, %delay ] + %b = load i32, ptr %p2 + %value = select i1 %use2, i32 %a, i32 %b + ret i32 %value +}