From 1882c25f124647ba5b5d798dc00c4cd9308536bf Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Thu, 2 Jun 2022 14:02:11 -0400 Subject: [PATCH] [InstCombine] add tests for mul with low-bit mask operand; NFC --- llvm/test/Transforms/InstCombine/mul.ll | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/mul.ll b/llvm/test/Transforms/InstCombine/mul.ll index 895ce433630c..e641e100345f 100644 --- a/llvm/test/Transforms/InstCombine/mul.ll +++ b/llvm/test/Transforms/InstCombine/mul.ll @@ -462,6 +462,58 @@ define <2 x i32> @signbit_mul_vec_commute(<2 x i32> %a, <2 x i32> %b) { ret <2 x i32> %e } +; (A & 1) * B --> (lowbit A) ? B : 0 + +define i32 @lowbit_mul(i32 %a, i32 %b) { +; CHECK-LABEL: @lowbit_mul( +; CHECK-NEXT: [[D:%.*]] = and i32 [[A:%.*]], 1 +; CHECK-NEXT: [[E:%.*]] = mul nuw i32 [[D]], [[B:%.*]] +; CHECK-NEXT: ret i32 [[E]] +; + %d = and i32 %a, 1 + %e = mul i32 %d, %b + ret i32 %e +} + +; (A & 1) * B --> (lowbit A) ? B : 0 + +define <2 x i17> @lowbit_mul_commute(<2 x i17> %a, <2 x i17> %p) { +; CHECK-LABEL: @lowbit_mul_commute( +; CHECK-NEXT: [[B:%.*]] = xor <2 x i17> [[P:%.*]], +; CHECK-NEXT: [[D:%.*]] = and <2 x i17> [[A:%.*]], +; CHECK-NEXT: [[E:%.*]] = mul nuw <2 x i17> [[B]], [[D]] +; CHECK-NEXT: ret <2 x i17> [[E]] +; + %b = xor <2 x i17> %p, ; thwart complexity-based canonicalization + %d = and <2 x i17> %a, + %e = mul <2 x i17> %b, %d + ret <2 x i17> %e +} + +define i32 @lowbit_mul_use(i32 %a, i32 %b) { +; CHECK-LABEL: @lowbit_mul_use( +; CHECK-NEXT: [[D:%.*]] = and i32 [[A:%.*]], 1 +; CHECK-NEXT: call void @use32(i32 [[D]]) +; CHECK-NEXT: [[E:%.*]] = mul nuw i32 [[D]], [[B:%.*]] +; CHECK-NEXT: ret i32 [[E]] +; + %d = and i32 %a, 1 + call void @use32(i32 %d) + %e = mul i32 %d, %b + ret i32 %e +} + +define i32 @not_lowbit_mul(i32 %a, i32 %b) { +; CHECK-LABEL: @not_lowbit_mul( +; CHECK-NEXT: [[D:%.*]] = and i32 [[A:%.*]], 2 +; CHECK-NEXT: [[E:%.*]] = mul i32 [[D]], [[B:%.*]] +; CHECK-NEXT: ret i32 [[E]] +; + %d = and i32 %a, 2 + %e = mul i32 %d, %b + ret i32 %e +} + define i32 @signsplat_mul(i32 %x) { ; CHECK-LABEL: @signsplat_mul( ; CHECK-NEXT: [[ISNEG:%.*]] = icmp slt i32 [[X:%.*]], 0