From 4c1dc65015ae8ba4b7e0ac56f4d88d29e712ce25 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Thu, 20 Jan 2022 14:41:01 -0500 Subject: [PATCH] [InstCombine] add/adjust tests for multiply with extended bool; NFC --- llvm/test/Transforms/InstCombine/mul.ll | 57 ++++++++++++++++++++----- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/llvm/test/Transforms/InstCombine/mul.ll b/llvm/test/Transforms/InstCombine/mul.ll index 76dc39598dc7..e99d1e9cfd18 100644 --- a/llvm/test/Transforms/InstCombine/mul.ll +++ b/llvm/test/Transforms/InstCombine/mul.ll @@ -103,30 +103,67 @@ define i32 @mul_bool(i32 %x, i1 %y) { ; CHECK-NEXT: ret i32 [[M]] ; %z = zext i1 %y to i32 - %m = mul i32 %x, %z + %m = mul i32 %z, %x ret i32 %m } -; Commute and test vector type. - define <2 x i32> @mul_bool_vec(<2 x i32> %x, <2 x i1> %y) { ; CHECK-LABEL: @mul_bool_vec( ; CHECK-NEXT: [[M:%.*]] = select <2 x i1> [[Y:%.*]], <2 x i32> [[X:%.*]], <2 x i32> zeroinitializer ; CHECK-NEXT: ret <2 x i32> [[M]] ; + %z = zext <2 x i1> %y to <2 x i32> + %m = mul <2 x i32> %z, %x + ret <2 x i32> %m +} + +define <2 x i32> @mul_bool_vec_commute(<2 x i32> %px, <2 x i1> %y) { +; CHECK-LABEL: @mul_bool_vec_commute( +; CHECK-NEXT: [[X:%.*]] = mul <2 x i32> [[PX:%.*]], [[PX]] +; CHECK-NEXT: [[M:%.*]] = select <2 x i1> [[Y:%.*]], <2 x i32> [[X]], <2 x i32> zeroinitializer +; CHECK-NEXT: ret <2 x i32> [[M]] +; + %x = mul <2 x i32> %px, %px ; thwart complexity-based canonicalization %z = zext <2 x i1> %y to <2 x i32> %m = mul <2 x i32> %x, %z ret <2 x i32> %m } -define <2 x i32> @mul_bool_vec_commute(<2 x i32> %x, <2 x i1> %y) { -; CHECK-LABEL: @mul_bool_vec_commute( -; CHECK-NEXT: [[M:%.*]] = select <2 x i1> [[Y:%.*]], <2 x i32> [[X:%.*]], <2 x i32> zeroinitializer -; CHECK-NEXT: ret <2 x i32> [[M]] +; X * C (when X is a sext boolean) --> X ? -C : 0 + +define i32 @mul_sext_bool(i1 %x) { +; CHECK-LABEL: @mul_sext_bool( +; CHECK-NEXT: [[S:%.*]] = sext i1 [[X:%.*]] to i32 +; CHECK-NEXT: [[M:%.*]] = mul nsw i32 [[S]], 42 +; CHECK-NEXT: ret i32 [[M]] ; - %z = zext <2 x i1> %y to <2 x i32> - %m = mul <2 x i32> %z, %x - ret <2 x i32> %m + %s = sext i1 %x to i32 + %m = mul i32 %s, 42 + ret i32 %m +} + +define i32 @mul_sext_bool_use(i1 %x) { +; CHECK-LABEL: @mul_sext_bool_use( +; CHECK-NEXT: [[S:%.*]] = sext i1 [[X:%.*]] to i32 +; CHECK-NEXT: call void @use32(i32 [[S]]) +; CHECK-NEXT: [[M:%.*]] = mul nsw i32 [[S]], 42 +; CHECK-NEXT: ret i32 [[M]] +; + %s = sext i1 %x to i32 + call void @use32(i32 %s) + %m = mul i32 %s, 42 + ret i32 %m +} + +define <2 x i8> @mul_sext_bool_vec(<2 x i1> %x) { +; CHECK-LABEL: @mul_sext_bool_vec( +; CHECK-NEXT: [[S:%.*]] = sext <2 x i1> [[X:%.*]] to <2 x i8> +; CHECK-NEXT: [[M:%.*]] = mul <2 x i8> [[S]], +; CHECK-NEXT: ret <2 x i8> [[M]] +; + %s = sext <2 x i1> %x to <2 x i8> + %m = mul <2 x i8> %s, + ret <2 x i8> %m } define <3 x i7> @mul_bools(<3 x i1> %x, <3 x i1> %y) {