From 4491c0dd4551cd44a644aa0a2ecc0c31e4496a99 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Fri, 29 Jun 2018 15:28:11 +0000 Subject: [PATCH] [InstCombine] add more tests for shuffle-binop folds; NFC The mul+shl tests add coverage for the fold enabled with D48678. The and+or tests are not handled yet; that's D48662. llvm-svn: 335984 --- .../Transforms/InstCombine/shuffle_select.ll | 74 ++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/llvm/test/Transforms/InstCombine/shuffle_select.ll b/llvm/test/Transforms/InstCombine/shuffle_select.ll index a19dd6297acb..6e8f26fce584 100644 --- a/llvm/test/Transforms/InstCombine/shuffle_select.ll +++ b/llvm/test/Transforms/InstCombine/shuffle_select.ll @@ -521,7 +521,6 @@ define <4 x i32> @shl_mul(<4 x i32> %v0) { ret <4 x i32> %t3 } -; PR37806 - https://bugs.llvm.org/show_bug.cgi?id=37806 ; Demanded elements + simplification can remove the mul alone, but that's not the best case. define <4 x i32> @mul_is_nop_shl(<4 x i32> %v0) { @@ -550,6 +549,32 @@ define <4 x i32> @shl_mul_not_constant_shift_amount(<4 x i32> %v0) { ret <4 x i32> %t3 } +; Try with 2 variable inputs. + +define <4 x i32> @mul_shl_2_vars(<4 x i32> %v0, <4 x i32> %v1) { +; CHECK-LABEL: @mul_shl_2_vars( +; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x i32> [[V0:%.*]], <4 x i32> [[V1:%.*]], <4 x i32> +; CHECK-NEXT: [[T3:%.*]] = mul nuw <4 x i32> [[TMP1]], +; CHECK-NEXT: ret <4 x i32> [[T3]] +; + %t1 = mul nuw <4 x i32> %v0, + %t2 = shl nuw <4 x i32> %v1, + %t3 = shufflevector <4 x i32> %t1, <4 x i32> %t2, <4 x i32> + ret <4 x i32> %t3 +} + +define <4 x i32> @shl_mul_2_vars(<4 x i32> %v0, <4 x i32> %v1) { +; CHECK-LABEL: @shl_mul_2_vars( +; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x i32> [[V0:%.*]], <4 x i32> [[V1:%.*]], <4 x i32> +; CHECK-NEXT: [[T3:%.*]] = mul <4 x i32> [[TMP1]], +; CHECK-NEXT: ret <4 x i32> [[T3]] +; + %t1 = shl nsw <4 x i32> %v0, + %t2 = mul nsw <4 x i32> %v1, + %t3 = shufflevector <4 x i32> %t1, <4 x i32> %t2, <4 x i32> + ret <4 x i32> %t3 +} + ; Or with constant can be converted to add to enable the fold. ; The 'shl' is here to allow analysis to determine that the 'or' can be transformed to 'add'. ; TODO: The 'or' constant is limited to a splat. @@ -586,3 +611,50 @@ define <4 x i8> @or_add(<4 x i8> %v) { ret <4 x i8> %t3 } +define <4 x i8> @or_add_not_enough_masking(<4 x i8> %v) { +; CHECK-LABEL: @or_add_not_enough_masking( +; CHECK-NEXT: [[V0:%.*]] = lshr <4 x i8> [[V:%.*]], +; CHECK-NEXT: [[T1:%.*]] = or <4 x i8> [[V0]], +; CHECK-NEXT: [[T2:%.*]] = add nuw nsw <4 x i8> [[V0]], +; CHECK-NEXT: [[T3:%.*]] = shufflevector <4 x i8> [[T1]], <4 x i8> [[T2]], <4 x i32> +; CHECK-NEXT: ret <4 x i8> [[T3]] +; + %v0 = lshr <4 x i8> %v, ; clear not enough top bits + %t1 = or <4 x i8> %v0, ; set some top bits + %t2 = add nsw nuw <4 x i8> %v0, ; this can't be converted to 'or' + %t3 = shufflevector <4 x i8> %t1, <4 x i8> %t2, <4 x i32> + ret <4 x i8> %t3 +} + +; Try with 2 variable inputs. + +define <4 x i32> @add_or_2_vars(<4 x i32> %v, <4 x i32> %v1) { +; CHECK-LABEL: @add_or_2_vars( +; CHECK-NEXT: [[V0:%.*]] = shl <4 x i32> [[V:%.*]], +; CHECK-NEXT: [[T1:%.*]] = add <4 x i32> [[V1:%.*]], +; CHECK-NEXT: [[T2:%.*]] = or <4 x i32> [[V0]], +; CHECK-NEXT: [[T3:%.*]] = shufflevector <4 x i32> [[T1]], <4 x i32> [[T2]], <4 x i32> +; CHECK-NEXT: ret <4 x i32> [[T3]] +; + %v0 = shl <4 x i32> %v, ; clear the bottom bits + %t1 = add <4 x i32> %v1, ; this can't be converted to 'or' + %t2 = or <4 x i32> %v0, ; set the bottom bits + %t3 = shufflevector <4 x i32> %t1, <4 x i32> %t2, <4 x i32> + ret <4 x i32> %t3 +} + +define <4 x i8> @or_add_2_vars(<4 x i8> %v, <4 x i8> %v1) { +; CHECK-LABEL: @or_add_2_vars( +; CHECK-NEXT: [[V0:%.*]] = lshr <4 x i8> [[V:%.*]], +; CHECK-NEXT: [[T1:%.*]] = or <4 x i8> [[V0]], +; CHECK-NEXT: [[T2:%.*]] = add nuw nsw <4 x i8> [[V1:%.*]], +; CHECK-NEXT: [[T3:%.*]] = shufflevector <4 x i8> [[T1]], <4 x i8> [[T2]], <4 x i32> +; CHECK-NEXT: ret <4 x i8> [[T3]] +; + %v0 = lshr <4 x i8> %v, ; clear the top bits + %t1 = or <4 x i8> %v0, ; set some top bits + %t2 = add nsw nuw <4 x i8> %v1, ; this can't be converted to 'or' + %t3 = shufflevector <4 x i8> %t1, <4 x i8> %t2, <4 x i32> + ret <4 x i8> %t3 +} +