From 5bc5c016c4bf81af010e3c4e74ec800b203caaf5 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 26 Dec 2020 21:47:14 +0100 Subject: [PATCH] [CVP] Add tests for select form of and/or (NFC) This tests their handling inside LVI. See D93065 for wider context. --- .../CorrelatedValuePropagation/basic.ll | 198 ++++++++++++++++++ 1 file changed, 198 insertions(+) diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/basic.ll b/llvm/test/Transforms/CorrelatedValuePropagation/basic.ll index 0c41bb6270f9..e4748e71baa5 100644 --- a/llvm/test/Transforms/CorrelatedValuePropagation/basic.ll +++ b/llvm/test/Transforms/CorrelatedValuePropagation/basic.ll @@ -1061,6 +1061,204 @@ exit2: ret i1 %cmp2 } +define void @select_and(i32 %a, i1* %p) { +; CHECK-LABEL: @select_and( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt i32 [[A:%.*]], -10 +; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 [[A]], 10 +; CHECK-NEXT: [[AND:%.*]] = select i1 [[CMP1]], i1 [[CMP2]], i1 false +; CHECK-NEXT: br i1 [[AND]], label [[GUARD:%.*]], label [[EXIT:%.*]] +; CHECK: guard: +; CHECK-NEXT: [[C1:%.*]] = icmp sgt i32 [[A]], 20 +; CHECK-NEXT: store i1 [[C1]], i1* [[P:%.*]], align 1 +; CHECK-NEXT: [[C2:%.*]] = icmp slt i32 [[A]], -20 +; CHECK-NEXT: store i1 [[C2]], i1* [[P]], align 1 +; CHECK-NEXT: br label [[EXIT]] +; CHECK: exit: +; CHECK-NEXT: ret void +; +entry: + %cmp1 = icmp sgt i32 %a, -10 + %cmp2 = icmp slt i32 %a, 10 + %and = select i1 %cmp1, i1 %cmp2, i1 false + br i1 %and, label %guard, label %exit + +guard: + %c1 = icmp sgt i32 %a, 20 + store i1 %c1, i1* %p + %c2 = icmp slt i32 %a, -20 + store i1 %c2, i1* %p + br label %exit + +exit: + ret void +} + +define void @select_and_wrong_const(i32 %a, i1* %p) { +; CHECK-LABEL: @select_and_wrong_const( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt i32 [[A:%.*]], -10 +; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 [[A]], 10 +; CHECK-NEXT: [[AND:%.*]] = select i1 [[CMP1]], i1 [[CMP2]], i1 true +; CHECK-NEXT: br i1 [[AND]], label [[GUARD:%.*]], label [[EXIT:%.*]] +; CHECK: guard: +; CHECK-NEXT: [[C1:%.*]] = icmp sgt i32 [[A]], 20 +; CHECK-NEXT: store i1 [[C1]], i1* [[P:%.*]], align 1 +; CHECK-NEXT: [[C2:%.*]] = icmp slt i32 [[A]], -20 +; CHECK-NEXT: store i1 [[C2]], i1* [[P]], align 1 +; CHECK-NEXT: br label [[EXIT]] +; CHECK: exit: +; CHECK-NEXT: ret void +; +entry: + %cmp1 = icmp sgt i32 %a, -10 + %cmp2 = icmp slt i32 %a, 10 + %and = select i1 %cmp1, i1 %cmp2, i1 true + br i1 %and, label %guard, label %exit + +guard: + %c1 = icmp sgt i32 %a, 20 + store i1 %c1, i1* %p + %c2 = icmp slt i32 %a, -20 + store i1 %c2, i1* %p + br label %exit + +exit: + ret void +} + +define void @select_and_wrong_operand(i32 %a, i1* %p) { +; CHECK-LABEL: @select_and_wrong_operand( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt i32 [[A:%.*]], -10 +; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 [[A]], 10 +; CHECK-NEXT: [[AND:%.*]] = select i1 [[CMP1]], i1 false, i1 [[CMP2]] +; CHECK-NEXT: br i1 [[AND]], label [[GUARD:%.*]], label [[EXIT:%.*]] +; CHECK: guard: +; CHECK-NEXT: [[C1:%.*]] = icmp sgt i32 [[A]], 20 +; CHECK-NEXT: store i1 [[C1]], i1* [[P:%.*]], align 1 +; CHECK-NEXT: [[C2:%.*]] = icmp slt i32 [[A]], -20 +; CHECK-NEXT: store i1 [[C2]], i1* [[P]], align 1 +; CHECK-NEXT: br label [[EXIT]] +; CHECK: exit: +; CHECK-NEXT: ret void +; +entry: + %cmp1 = icmp sgt i32 %a, -10 + %cmp2 = icmp slt i32 %a, 10 + %and = select i1 %cmp1, i1 false, i1 %cmp2 + br i1 %and, label %guard, label %exit + +guard: + %c1 = icmp sgt i32 %a, 20 + store i1 %c1, i1* %p + %c2 = icmp slt i32 %a, -20 + store i1 %c2, i1* %p + br label %exit + +exit: + ret void +} + +define void @select_or(i32 %a, i1* %p) { +; CHECK-LABEL: @select_or( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 [[A:%.*]], -10 +; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i32 [[A]], 10 +; CHECK-NEXT: [[OR:%.*]] = select i1 [[CMP1]], i1 true, i1 [[CMP2]] +; CHECK-NEXT: br i1 [[OR]], label [[EXIT:%.*]], label [[GUARD:%.*]] +; CHECK: guard: +; CHECK-NEXT: [[C1:%.*]] = icmp sgt i32 [[A]], 20 +; CHECK-NEXT: store i1 [[C1]], i1* [[P:%.*]], align 1 +; CHECK-NEXT: [[C2:%.*]] = icmp slt i32 [[A]], -20 +; CHECK-NEXT: store i1 [[C2]], i1* [[P]], align 1 +; CHECK-NEXT: br label [[EXIT]] +; CHECK: exit: +; CHECK-NEXT: ret void +; +entry: + %cmp1 = icmp slt i32 %a, -10 + %cmp2 = icmp sgt i32 %a, 10 + %or = select i1 %cmp1, i1 true, i1 %cmp2 + br i1 %or, label %exit, label %guard + +guard: + %c1 = icmp sgt i32 %a, 20 + store i1 %c1, i1* %p + %c2 = icmp slt i32 %a, -20 + store i1 %c2, i1* %p + br label %exit + +exit: + ret void +} + +define void @select_or_wrong_const(i32 %a, i1* %p) { +; CHECK-LABEL: @select_or_wrong_const( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 [[A:%.*]], -10 +; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i32 [[A]], 10 +; CHECK-NEXT: [[OR:%.*]] = select i1 [[CMP1]], i1 false, i1 [[CMP2]] +; CHECK-NEXT: br i1 [[OR]], label [[EXIT:%.*]], label [[GUARD:%.*]] +; CHECK: guard: +; CHECK-NEXT: [[C1:%.*]] = icmp sgt i32 [[A]], 20 +; CHECK-NEXT: store i1 [[C1]], i1* [[P:%.*]], align 1 +; CHECK-NEXT: [[C2:%.*]] = icmp slt i32 [[A]], -20 +; CHECK-NEXT: store i1 [[C2]], i1* [[P]], align 1 +; CHECK-NEXT: br label [[EXIT]] +; CHECK: exit: +; CHECK-NEXT: ret void +; +entry: + %cmp1 = icmp slt i32 %a, -10 + %cmp2 = icmp sgt i32 %a, 10 + %or = select i1 %cmp1, i1 false, i1 %cmp2 + br i1 %or, label %exit, label %guard + +guard: + %c1 = icmp sgt i32 %a, 20 + store i1 %c1, i1* %p + %c2 = icmp slt i32 %a, -20 + store i1 %c2, i1* %p + br label %exit + +exit: + ret void +} + +define void @select_or_wrong_operand(i32 %a, i1* %p) { +; CHECK-LABEL: @select_or_wrong_operand( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 [[A:%.*]], -10 +; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i32 [[A]], 10 +; CHECK-NEXT: [[OR:%.*]] = select i1 [[CMP1]], i1 [[CMP2]], i1 true +; CHECK-NEXT: br i1 [[OR]], label [[EXIT:%.*]], label [[GUARD:%.*]] +; CHECK: guard: +; CHECK-NEXT: [[C1:%.*]] = icmp sgt i32 [[A]], 20 +; CHECK-NEXT: store i1 [[C1]], i1* [[P:%.*]], align 1 +; CHECK-NEXT: [[C2:%.*]] = icmp slt i32 [[A]], -20 +; CHECK-NEXT: store i1 [[C2]], i1* [[P]], align 1 +; CHECK-NEXT: br label [[EXIT]] +; CHECK: exit: +; CHECK-NEXT: ret void +; +entry: + %cmp1 = icmp slt i32 %a, -10 + %cmp2 = icmp sgt i32 %a, 10 + %or = select i1 %cmp1, i1 %cmp2, i1 true + br i1 %or, label %exit, label %guard + +guard: + %c1 = icmp sgt i32 %a, 20 + store i1 %c1, i1* %p + %c2 = icmp slt i32 %a, -20 + store i1 %c2, i1* %p + br label %exit + +exit: + ret void +} + declare i32 @llvm.uadd.sat.i32(i32, i32) declare i32 @llvm.usub.sat.i32(i32, i32) declare i32 @llvm.sadd.sat.i32(i32, i32)