diff options
| author | Sanjay Patel <spatel@rotateright.com> | 2018-06-29 15:28:11 +0000 |
|---|---|---|
| committer | Sanjay Patel <spatel@rotateright.com> | 2018-06-29 15:28:11 +0000 |
| commit | 4491c0dd4551cd44a644aa0a2ecc0c31e4496a99 (patch) | |
| tree | 2748c2309970ed1a3f8c6f3c3e176d37fa9f69ad | |
| parent | 3007b385fa0b20bf48fae04c6b1a0e417a72ecd0 (diff) | |
| download | bcm5719-llvm-4491c0dd4551cd44a644aa0a2ecc0c31e4496a99.tar.gz bcm5719-llvm-4491c0dd4551cd44a644aa0a2ecc0c31e4496a99.zip | |
[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
| -rw-r--r-- | llvm/test/Transforms/InstCombine/shuffle_select.ll | 74 |
1 files changed, 73 insertions, 1 deletions
diff --git a/llvm/test/Transforms/InstCombine/shuffle_select.ll b/llvm/test/Transforms/InstCombine/shuffle_select.ll index a19dd6297ac..6e8f26fce58 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> <i32 4, i32 5, i32 2, i32 3> +; CHECK-NEXT: [[T3:%.*]] = mul nuw <4 x i32> [[TMP1]], <i32 32, i32 64, i32 3, i32 4> +; CHECK-NEXT: ret <4 x i32> [[T3]] +; + %t1 = mul nuw <4 x i32> %v0, <i32 1, i32 2, i32 3, i32 4> + %t2 = shl nuw <4 x i32> %v1, <i32 5, i32 6, i32 7, i32 8> + %t3 = shufflevector <4 x i32> %t1, <4 x i32> %t2, <4 x i32> <i32 4, i32 5, i32 2, i32 3> + 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> <i32 4, i32 undef, i32 2, i32 3> +; CHECK-NEXT: [[T3:%.*]] = mul <4 x i32> [[TMP1]], <i32 5, i32 undef, i32 8, i32 16> +; CHECK-NEXT: ret <4 x i32> [[T3]] +; + %t1 = shl nsw <4 x i32> %v0, <i32 1, i32 2, i32 3, i32 4> + %t2 = mul nsw <4 x i32> %v1, <i32 5, i32 6, i32 7, i32 8> + %t3 = shufflevector <4 x i32> %t1, <4 x i32> %t2, <4 x i32> <i32 4, i32 undef, i32 2, i32 3> + 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:%.*]], <i8 1, i8 1, i8 1, i8 1> +; CHECK-NEXT: [[T1:%.*]] = or <4 x i8> [[V0]], <i8 undef, i8 undef, i8 -64, i8 -64> +; CHECK-NEXT: [[T2:%.*]] = add nuw nsw <4 x i8> [[V0]], <i8 1, i8 2, i8 undef, i8 undef> +; CHECK-NEXT: [[T3:%.*]] = shufflevector <4 x i8> [[T1]], <4 x i8> [[T2]], <4 x i32> <i32 4, i32 5, i32 2, i32 3> +; CHECK-NEXT: ret <4 x i8> [[T3]] +; + %v0 = lshr <4 x i8> %v, <i8 1, i8 1, i8 1, i8 1> ; clear not enough top bits + %t1 = or <4 x i8> %v0, <i8 192, i8 192, i8 192, i8 192> ; set some top bits + %t2 = add nsw nuw <4 x i8> %v0, <i8 1, i8 2, i8 3, i8 4> ; this can't be converted to 'or' + %t3 = shufflevector <4 x i8> %t1, <4 x i8> %t2, <4 x i32> <i32 4, i32 5, i32 2, i32 3> + 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:%.*]], <i32 5, i32 5, i32 5, i32 5> +; CHECK-NEXT: [[T1:%.*]] = add <4 x i32> [[V1:%.*]], <i32 undef, i32 undef, i32 65536, i32 65537> +; CHECK-NEXT: [[T2:%.*]] = or <4 x i32> [[V0]], <i32 31, i32 31, i32 undef, i32 undef> +; CHECK-NEXT: [[T3:%.*]] = shufflevector <4 x i32> [[T1]], <4 x i32> [[T2]], <4 x i32> <i32 4, i32 5, i32 2, i32 3> +; CHECK-NEXT: ret <4 x i32> [[T3]] +; + %v0 = shl <4 x i32> %v, <i32 5, i32 5, i32 5, i32 5> ; clear the bottom bits + %t1 = add <4 x i32> %v1, <i32 65534, i32 65535, i32 65536, i32 65537> ; this can't be converted to 'or' + %t2 = or <4 x i32> %v0, <i32 31, i32 31, i32 31, i32 31> ; set the bottom bits + %t3 = shufflevector <4 x i32> %t1, <4 x i32> %t2, <4 x i32> <i32 4, i32 5, i32 2, i32 3> + 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:%.*]], <i8 3, i8 3, i8 3, i8 3> +; CHECK-NEXT: [[T1:%.*]] = or <4 x i8> [[V0]], <i8 undef, i8 undef, i8 -64, i8 -64> +; CHECK-NEXT: [[T2:%.*]] = add nuw nsw <4 x i8> [[V1:%.*]], <i8 1, i8 2, i8 undef, i8 undef> +; CHECK-NEXT: [[T3:%.*]] = shufflevector <4 x i8> [[T1]], <4 x i8> [[T2]], <4 x i32> <i32 4, i32 5, i32 2, i32 3> +; CHECK-NEXT: ret <4 x i8> [[T3]] +; + %v0 = lshr <4 x i8> %v, <i8 3, i8 3, i8 3, i8 3> ; clear the top bits + %t1 = or <4 x i8> %v0, <i8 192, i8 192, i8 192, i8 192> ; set some top bits + %t2 = add nsw nuw <4 x i8> %v1, <i8 1, i8 2, i8 3, i8 4> ; this can't be converted to 'or' + %t3 = shufflevector <4 x i8> %t1, <4 x i8> %t2, <4 x i32> <i32 4, i32 5, i32 2, i32 3> + ret <4 x i8> %t3 +} + |

