From fae7d6886e4ed8d75a8efa6f74562a314d2762aa Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Tue, 12 Oct 2021 11:47:03 -0400 Subject: [PATCH] [InstCombine] add tests with nsw/nuw for mul-of-select; NFC --- .../Transforms/InstCombine/mul-inseltpoison.ll | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/mul-inseltpoison.ll b/llvm/test/Transforms/InstCombine/mul-inseltpoison.ll index 4b7af92..5c66ea0 100644 --- a/llvm/test/Transforms/InstCombine/mul-inseltpoison.ll +++ b/llvm/test/Transforms/InstCombine/mul-inseltpoison.ll @@ -718,6 +718,50 @@ define i32 @negate_if_false(i32 %x, i1 %cond) { ret i32 %r } +define i32 @negate_if_true_nsw(i32 %x, i1 %cond) { +; CHECK-LABEL: @negate_if_true_nsw( +; CHECK-NEXT: [[TMP1:%.*]] = sub i32 0, [[X:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[X]] +; CHECK-NEXT: ret i32 [[TMP2]] +; + %sel = select i1 %cond, i32 -1, i32 1 + %r = mul nsw i32 %sel, %x + ret i32 %r +} + +define i32 @negate_if_true_nuw(i32 %x, i1 %cond) { +; CHECK-LABEL: @negate_if_true_nuw( +; CHECK-NEXT: [[TMP1:%.*]] = sub i32 0, [[X:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[X]] +; CHECK-NEXT: ret i32 [[TMP2]] +; + %sel = select i1 %cond, i32 -1, i32 1 + %r = mul nuw i32 %sel, %x + ret i32 %r +} + +define i32 @negate_if_false_nsw(i32 %x, i1 %cond) { +; CHECK-LABEL: @negate_if_false_nsw( +; CHECK-NEXT: [[TMP1:%.*]] = sub i32 0, [[X:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[COND:%.*]], i32 [[X]], i32 [[TMP1]] +; CHECK-NEXT: ret i32 [[TMP2]] +; + %sel = select i1 %cond, i32 1, i32 -1 + %r = mul nsw i32 %sel, %x + ret i32 %r +} + +define i32 @negate_if_false_nuw(i32 %x, i1 %cond) { +; CHECK-LABEL: @negate_if_false_nuw( +; CHECK-NEXT: [[TMP1:%.*]] = sub i32 0, [[X:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[COND:%.*]], i32 [[X]], i32 [[TMP1]] +; CHECK-NEXT: ret i32 [[TMP2]] +; + %sel = select i1 %cond, i32 1, i32 -1 + %r = mul nuw i32 %sel, %x + ret i32 %r +} + define <2 x i8> @negate_if_true_commute(<2 x i8> %px, i1 %cond) { ; CHECK-LABEL: @negate_if_true_commute( ; CHECK-NEXT: [[X:%.*]] = sdiv <2 x i8> , [[PX:%.*]] -- 2.7.4