[llvm] 8371a4c - [Test][AggressiveInstCombine] Add test for truncation of vector instructions
Anton Afanasyev via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 16 01:24:54 PDT 2021
Author: Anton Afanasyev
Date: 2021-09-16T11:24:30+03:00
New Revision: 8371a4c9d55997fdc45effbfa5d38d1f19ae3473
URL: https://github.com/llvm/llvm-project/commit/8371a4c9d55997fdc45effbfa5d38d1f19ae3473
DIFF: https://github.com/llvm/llvm-project/commit/8371a4c9d55997fdc45effbfa5d38d1f19ae3473.diff
LOG: [Test][AggressiveInstCombine] Add test for truncation of vector instructions
Precommit test for D109236
Added:
llvm/test/Transforms/AggressiveInstCombine/trunc_vector_instrs.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Transforms/AggressiveInstCombine/trunc_vector_instrs.ll b/llvm/test/Transforms/AggressiveInstCombine/trunc_vector_instrs.ll
new file mode 100644
index 0000000000000..2702ab821b936
--- /dev/null
+++ b/llvm/test/Transforms/AggressiveInstCombine/trunc_vector_instrs.ll
@@ -0,0 +1,92 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -aggressive-instcombine -S | FileCheck %s
+
+define <4 x i16> @shuffle(<2 x i8> %a, <2 x i8> %b) {
+; CHECK-LABEL: @shuffle(
+; CHECK-NEXT: [[ZEXTA:%.*]] = zext <2 x i8> [[A:%.*]] to <2 x i32>
+; CHECK-NEXT: [[ZEXTB:%.*]] = zext <2 x i8> [[B:%.*]] to <2 x i32>
+; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <2 x i32> [[ZEXTA]], <2 x i32> [[ZEXTB]], <4 x i32> <i32 3, i32 2, i32 1, i32 0>
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc <4 x i32> [[SHUF]] to <4 x i16>
+; CHECK-NEXT: ret <4 x i16> [[TRUNC]]
+;
+ %zexta = zext <2 x i8> %a to <2 x i32>
+ %zextb = zext <2 x i8> %b to <2 x i32>
+ %shuf = shufflevector <2 x i32> %zexta, <2 x i32> %zextb, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
+ %trunc = trunc <4 x i32> %shuf to <4 x i16>
+ ret <4 x i16> %trunc
+}
+
+define <2 x i16> @unary_shuffle(<2 x i8> %a) {
+; CHECK-LABEL: @unary_shuffle(
+; CHECK-NEXT: [[ZEXTA:%.*]] = zext <2 x i8> [[A:%.*]] to <2 x i32>
+; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <2 x i32> [[ZEXTA]], <2 x i32> undef, <2 x i32> <i32 1, i32 0>
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc <2 x i32> [[SHUF]] to <2 x i16>
+; CHECK-NEXT: ret <2 x i16> [[TRUNC]]
+;
+ %zexta = zext <2 x i8> %a to <2 x i32>
+ %shuf = shufflevector <2 x i32> %zexta, <2 x i32> undef, <2 x i32> <i32 1, i32 0>
+ %trunc = trunc <2 x i32> %shuf to <2 x i16>
+ ret <2 x i16> %trunc
+}
+
+define <4 x i16> @const_shuffle() {
+; CHECK-LABEL: @const_shuffle(
+; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <2 x i32> <i32 1, i32 2>, <2 x i32> <i32 3, i32 7>, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc <4 x i32> [[SHUF]] to <4 x i16>
+; CHECK-NEXT: ret <4 x i16> [[TRUNC]]
+;
+ %shuf = shufflevector <2 x i32> <i32 1, i32 2>, <2 x i32> <i32 3, i32 7>, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
+ %trunc = trunc <4 x i32> %shuf to <4 x i16>
+ ret <4 x i16> %trunc
+}
+
+
+define <2 x i16> @extract_insert(<2 x i8> %a, <2 x i8> %b) {
+; CHECK-LABEL: @extract_insert(
+; CHECK-NEXT: [[ZEXTA:%.*]] = zext <2 x i8> [[A:%.*]] to <2 x i32>
+; CHECK-NEXT: [[ZEXTB:%.*]] = zext <2 x i8> [[B:%.*]] to <2 x i32>
+; CHECK-NEXT: [[EXTR:%.*]] = extractelement <2 x i32> [[ZEXTA]], i32 0
+; CHECK-NEXT: [[INSR:%.*]] = insertelement <2 x i32> [[ZEXTB]], i32 [[EXTR]], i32 1
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc <2 x i32> [[INSR]] to <2 x i16>
+; CHECK-NEXT: ret <2 x i16> [[TRUNC]]
+;
+ %zexta = zext <2 x i8> %a to <2 x i32>
+ %zextb = zext <2 x i8> %b to <2 x i32>
+ %extr = extractelement <2 x i32> %zexta, i32 0
+ %insr = insertelement <2 x i32> %zextb, i32 %extr, i32 1
+ %trunc = trunc <2 x i32> %insr to <2 x i16>
+ ret <2 x i16> %trunc
+}
+
+define <2 x i16> @insert_poison(i8 %a) {
+; CHECK-LABEL: @insert_poison(
+; CHECK-NEXT: [[ZEXTA:%.*]] = zext i8 [[A:%.*]] to i32
+; CHECK-NEXT: [[INSR:%.*]] = insertelement <2 x i32> poison, i32 [[ZEXTA]], i32 0
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc <2 x i32> [[INSR]] to <2 x i16>
+; CHECK-NEXT: ret <2 x i16> [[TRUNC]]
+;
+ %zexta = zext i8 %a to i32
+ %insr = insertelement <2 x i32> poison, i32 %zexta, i32 0
+ %trunc = trunc <2 x i32> %insr to <2 x i16>
+ ret <2 x i16> %trunc
+}
+
+; This demonstrates test not folded by 'opt -instcombine'
+define <2 x i16> @extract_mul_insert(<2 x i8> %x) {
+; CHECK-LABEL: @extract_mul_insert(
+; CHECK-NEXT: [[ZEXT:%.*]] = zext <2 x i8> [[X:%.*]] to <2 x i32>
+; CHECK-NEXT: [[LSHR:%.*]] = lshr <2 x i32> [[ZEXT]], <i32 4, i32 5>
+; CHECK-NEXT: [[EXTR:%.*]] = extractelement <2 x i32> [[LSHR]], i32 1
+; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[EXTR]], 5
+; CHECK-NEXT: [[INSR:%.*]] = insertelement <2 x i32> [[LSHR]], i32 [[MUL]], i32 1
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc <2 x i32> [[INSR]] to <2 x i16>
+; CHECK-NEXT: ret <2 x i16> [[TRUNC]]
+;
+ %zext = zext <2 x i8> %x to <2 x i32>
+ %lshr = lshr <2 x i32> %zext, <i32 4, i32 5>
+ %extr = extractelement <2 x i32> %lshr, i32 1
+ %mul = mul i32 %extr, 5
+ %insr = insertelement <2 x i32> %lshr, i32 %mul, i32 1
+ %trunc = trunc <2 x i32> %insr to <2 x i16>
+ ret <2 x i16> %trunc
+}
More information about the llvm-commits
mailing list