From 69daa2fa617d146beb3eff190973f5e786f1b5e5 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Sun, 16 Jan 2022 13:01:43 -0500 Subject: [PATCH] [InstCombine] add tests for binop with flags and select op; NFC --- llvm/test/Transforms/InstCombine/select-2.ll | 66 ++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/select-2.ll b/llvm/test/Transforms/InstCombine/select-2.ll index b0f39c1..43e4ca8 100644 --- a/llvm/test/Transforms/InstCombine/select-2.ll +++ b/llvm/test/Transforms/InstCombine/select-2.ll @@ -42,3 +42,69 @@ define float @t3(float %x, float %y) { %t3 = fadd fast float %t2, 1.0 ret float %t3 } + +define i8 @ashr_exact_poison_constant_fold(i1 %b, i8 %x) { +; CHECK-LABEL: @ashr_exact_poison_constant_fold( +; CHECK-NEXT: [[X_OP:%.*]] = ashr i8 [[X:%.*]], 3 +; CHECK-NEXT: [[R:%.*]] = select i1 [[B:%.*]], i8 [[X_OP]], i8 5 +; CHECK-NEXT: ret i8 [[R]] +; + %s = select i1 %b, i8 %x, i8 42 + %r = ashr exact i8 %s, 3 + ret i8 %r +} + +define i8 @ashr_exact(i1 %b, i8 %x) { +; CHECK-LABEL: @ashr_exact( +; CHECK-NEXT: [[X_OP:%.*]] = ashr i8 [[X:%.*]], 3 +; CHECK-NEXT: [[R:%.*]] = select i1 [[B:%.*]], i8 [[X_OP]], i8 2 +; CHECK-NEXT: ret i8 [[R]] +; + %s = select i1 %b, i8 %x, i8 16 + %r = ashr exact i8 %s, 3 + ret i8 %r +} + +define i8 @shl_nsw_nuw_poison_constant_fold(i1 %b, i8 %x) { +; CHECK-LABEL: @shl_nsw_nuw_poison_constant_fold( +; CHECK-NEXT: [[X_OP:%.*]] = shl i8 16, [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = select i1 [[B:%.*]], i8 -128, i8 [[X_OP]] +; CHECK-NEXT: ret i8 [[R]] +; + %s = select i1 %b, i8 3, i8 %x + %r = shl nsw nuw i8 16, %s + ret i8 %r +} + +define i8 @shl_nsw_nuw(i1 %b, i8 %x) { +; CHECK-LABEL: @shl_nsw_nuw( +; CHECK-NEXT: [[X_OP:%.*]] = shl i8 7, [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = select i1 [[B:%.*]], i8 56, i8 [[X_OP]] +; CHECK-NEXT: ret i8 [[R]] +; + %s = select i1 %b, i8 3, i8 %x + %r = shl nsw nuw i8 7, %s + ret i8 %r +} + +define i8 @add_nsw_poison_constant_fold(i1 %b, i8 %x) { +; CHECK-LABEL: @add_nsw_poison_constant_fold( +; CHECK-NEXT: [[X_OP:%.*]] = add i8 [[X:%.*]], 64 +; CHECK-NEXT: [[R:%.*]] = select i1 [[B:%.*]], i8 [[X_OP]], i8 -127 +; CHECK-NEXT: ret i8 [[R]] +; + %s = select i1 %b, i8 %x, i8 65 + %r = add nsw i8 %s, 64 + ret i8 %r +} + +define i8 @add_nsw(i1 %b, i8 %x) { +; CHECK-LABEL: @add_nsw( +; CHECK-NEXT: [[X_OP:%.*]] = add i8 [[X:%.*]], 64 +; CHECK-NEXT: [[R:%.*]] = select i1 [[B:%.*]], i8 [[X_OP]], i8 71 +; CHECK-NEXT: ret i8 [[R]] +; + %s = select i1 %b, i8 %x, i8 7 + %r = add nsw i8 %s, 64 + ret i8 %r +} -- 2.7.4