llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-llvm-transforms Author: Pedro Lobo (pedroclobo) <details> <summary>Changes</summary> Add vector tests for the `bitinsert` and `bitextract` folds that already work on scalar types. Vectors were not implemented when the following landed, so none of them had vector tests: - ConstantFolding's `poison` early exits (#<!-- -->229115). - InstSimplify's out-of-range splat offsets, full-width forms, and `bitextract`/`bitinsert` round trips (#<!-- -->229125). - InstCombine's full-width `bitcast` folds (#<!-- -->229147). It also adds negative tests where only some elements of the offset are out of range or `poison`. Those elements become `poison`. --- Full diff: https://github.com/llvm/llvm-project/pull/240197.diff 3 Files Affected: - (modified) llvm/test/Transforms/InstCombine/bitinsert-bitextract.ll (+93) - (modified) llvm/test/Transforms/InstSimplify/ConstProp/bitinsert-bitextract.ll (+16) - (modified) llvm/test/Transforms/InstSimplify/bitinsert-bitextract.ll (+140) ``````````diff diff --git a/llvm/test/Transforms/InstCombine/bitinsert-bitextract.ll b/llvm/test/Transforms/InstCombine/bitinsert-bitextract.ll index 59aef89ea5d99f..5ed8b3f7f2a9ef 100644 --- a/llvm/test/Transforms/InstCombine/bitinsert-bitextract.ll +++ b/llvm/test/Transforms/InstCombine/bitinsert-bitextract.ll @@ -148,3 +148,96 @@ define b64 @neg_bitinsert_variable_offset(b64 %x, i64 %y, i32 %n) { %r = bitinsert b64 %x, i64 %y, i32 %n ret b64 %r } + +define <2 x i64> @bitextract_vec_full_width(<2 x b64> %x) { +; CHECK-LABEL: define <2 x i64> @bitextract_vec_full_width( +; CHECK-SAME: <2 x b64> [[X:%.*]]) { +; CHECK-NEXT: [[R:%.*]] = bitcast <2 x b64> [[X]] to <2 x i64> +; CHECK-NEXT: ret <2 x i64> [[R]] +; + %r = bitextract <2 x i64>, <2 x b64> %x, <2 x i32> zeroinitializer + ret <2 x i64> %r +} + +define <2 x ptr> @bitextract_vec_full_width_ptr(<2 x b64> %x) { +; CHECK-LABEL: define <2 x ptr> @bitextract_vec_full_width_ptr( +; CHECK-SAME: <2 x b64> [[X:%.*]]) { +; CHECK-NEXT: [[R:%.*]] = bitcast <2 x b64> [[X]] to <2 x ptr> +; CHECK-NEXT: ret <2 x ptr> [[R]] +; + %r = bitextract <2 x ptr>, <2 x b64> %x, <2 x i32> zeroinitializer + ret <2 x ptr> %r +} + +define <vscale x 2 x double> @bitextract_scalable_vec_full_width(<vscale x 2 x b64> %x) { +; CHECK-LABEL: define <vscale x 2 x double> @bitextract_scalable_vec_full_width( +; CHECK-SAME: <vscale x 2 x b64> [[X:%.*]]) { +; CHECK-NEXT: [[R:%.*]] = bitcast <vscale x 2 x b64> [[X]] to <vscale x 2 x double> +; CHECK-NEXT: ret <vscale x 2 x double> [[R]] +; + %r = bitextract <vscale x 2 x double>, <vscale x 2 x b64> %x, <vscale x 2 x i32> zeroinitializer + ret <vscale x 2 x double> %r +} + +define <2 x b64> @bitinsert_vec_full_width(<2 x b64> %x, <2 x i64> %y) { +; CHECK-LABEL: define <2 x b64> @bitinsert_vec_full_width( +; CHECK-SAME: <2 x b64> [[X:%.*]], <2 x i64> [[Y:%.*]]) { +; CHECK-NEXT: [[R:%.*]] = bitcast <2 x i64> [[Y]] to <2 x b64> +; CHECK-NEXT: ret <2 x b64> [[R]] +; + %r = bitinsert <2 x b64> %x, <2 x i64> %y, <2 x i32> zeroinitializer + ret <2 x b64> %r +} + +define <2 x b64> @bitinsert_vec_full_width_ptr(<2 x b64> %x, <2 x ptr> %y) { +; CHECK-LABEL: define <2 x b64> @bitinsert_vec_full_width_ptr( +; CHECK-SAME: <2 x b64> [[X:%.*]], <2 x ptr> [[Y:%.*]]) { +; CHECK-NEXT: [[R:%.*]] = bitcast <2 x ptr> [[Y]] to <2 x b64> +; CHECK-NEXT: ret <2 x b64> [[R]] +; + %r = bitinsert <2 x b64> %x, <2 x ptr> %y, <2 x i32> zeroinitializer + ret <2 x b64> %r +} + +define <vscale x 2 x b64> @bitinsert_scalable_vec_full_width(<vscale x 2 x b64> %x, <vscale x 2 x double> %y) { +; CHECK-LABEL: define <vscale x 2 x b64> @bitinsert_scalable_vec_full_width( +; CHECK-SAME: <vscale x 2 x b64> [[X:%.*]], <vscale x 2 x double> [[Y:%.*]]) { +; CHECK-NEXT: [[R:%.*]] = bitcast <vscale x 2 x double> [[Y]] to <vscale x 2 x b64> +; CHECK-NEXT: ret <vscale x 2 x b64> [[R]] +; + %r = bitinsert <vscale x 2 x b64> %x, <vscale x 2 x double> %y, <vscale x 2 x i32> zeroinitializer + ret <vscale x 2 x b64> %r +} + +; The elements are narrower than the source elements. +define <2 x i32> @neg_bitextract_vec_partial(<2 x b64> %x) { +; CHECK-LABEL: define <2 x i32> @neg_bitextract_vec_partial( +; CHECK-SAME: <2 x b64> [[X:%.*]]) { +; CHECK-NEXT: [[R:%.*]] = bitextract <2 x i32>, <2 x b64> [[X]], <2 x i32> zeroinitializer +; CHECK-NEXT: ret <2 x i32> [[R]] +; + %r = bitextract <2 x i32>, <2 x b64> %x, <2 x i32> zeroinitializer + ret <2 x i32> %r +} + +; The offset may not be zero. +define <2 x i64> @neg_bitextract_vec_variable_offset(<2 x b64> %x, <2 x i32> %n) { +; CHECK-LABEL: define <2 x i64> @neg_bitextract_vec_variable_offset( +; CHECK-SAME: <2 x b64> [[X:%.*]], <2 x i32> [[N:%.*]]) { +; CHECK-NEXT: [[R:%.*]] = bitextract <2 x i64>, <2 x b64> [[X]], <2 x i32> [[N]] +; CHECK-NEXT: ret <2 x i64> [[R]] +; + %r = bitextract <2 x i64>, <2 x b64> %x, <2 x i32> %n + ret <2 x i64> %r +} + +; The elements are narrower than the base elements. +define <2 x b64> @neg_bitinsert_vec_partial(<2 x b64> %x, <2 x i32> %y) { +; CHECK-LABEL: define <2 x b64> @neg_bitinsert_vec_partial( +; CHECK-SAME: <2 x b64> [[X:%.*]], <2 x i32> [[Y:%.*]]) { +; CHECK-NEXT: [[R:%.*]] = bitinsert <2 x b64> [[X]], <2 x i32> [[Y]], <2 x i32> zeroinitializer +; CHECK-NEXT: ret <2 x b64> [[R]] +; + %r = bitinsert <2 x b64> %x, <2 x i32> %y, <2 x i32> zeroinitializer + ret <2 x b64> %r +} diff --git a/llvm/test/Transforms/InstSimplify/ConstProp/bitinsert-bitextract.ll b/llvm/test/Transforms/InstSimplify/ConstProp/bitinsert-bitextract.ll index 5ea3d4b7b5bec2..cd858b461a1c0a 100644 --- a/llvm/test/Transforms/InstSimplify/ConstProp/bitinsert-bitextract.ll +++ b/llvm/test/Transforms/InstSimplify/ConstProp/bitinsert-bitextract.ll @@ -378,6 +378,22 @@ define b256 @neg_bitinsert_ppc_fp128() { ret b256 %r } +define <2 x i8> @bitextract_vec_poison_src() { +; CHECK-LABEL: define <2 x i8> @bitextract_vec_poison_src() { +; CHECK-NEXT: ret <2 x i8> poison +; + %r = bitextract <2 x i8>, <2 x b32> poison, <2 x i32> splat (i32 8) + ret <2 x i8> %r +} + +define <2 x b32> @bitinsert_vec_poison_poison() { +; CHECK-LABEL: define <2 x b32> @bitinsert_vec_poison_poison() { +; CHECK-NEXT: ret <2 x b32> poison +; + %r = bitinsert <2 x b32> poison, <2 x i8> poison, <2 x i32> splat (i32 8) + ret <2 x b32> %r +} + ; TODO: Fold vectors element by element. define <vscale x 4 x i8> @bitextract_scalable_vec_splat() { ; CHECK-LABEL: define <vscale x 4 x i8> @bitextract_scalable_vec_splat() { diff --git a/llvm/test/Transforms/InstSimplify/bitinsert-bitextract.ll b/llvm/test/Transforms/InstSimplify/bitinsert-bitextract.ll index 448f1f197e8518..7c8252e9f63fc9 100644 --- a/llvm/test/Transforms/InstSimplify/bitinsert-bitextract.ll +++ b/llvm/test/Transforms/InstSimplify/bitinsert-bitextract.ll @@ -295,6 +295,37 @@ define b32 @neg_bitinsert_bitextract_other_offset(b32 %x) { ret b32 %r } +define <4 x i8> @bitextract_vec_out_of_range(<4 x b32> %x) { +; CHECK-LABEL: define <4 x i8> @bitextract_vec_out_of_range( +; CHECK-SAME: <4 x b32> [[X:%.*]]) { +; CHECK-NEXT: ret <4 x i8> poison +; + %r = bitextract <4 x i8>, <4 x b32> %x, <4 x i32> splat (i32 25) + ret <4 x i8> %r +} + +; The last bits of each element are in range. +define <4 x i8> @neg_bitextract_vec_in_range(<4 x b32> %x) { +; CHECK-LABEL: define <4 x i8> @neg_bitextract_vec_in_range( +; CHECK-SAME: <4 x b32> [[X:%.*]]) { +; CHECK-NEXT: [[R:%.*]] = bitextract <4 x i8>, <4 x b32> [[X]], <4 x i32> splat (i32 24) +; CHECK-NEXT: ret <4 x i8> [[R]] +; + %r = bitextract <4 x i8>, <4 x b32> %x, <4 x i32> splat (i32 24) + ret <4 x i8> %r +} + +; Only the last lane is out of range. +define <4 x i8> @neg_bitextract_vec_non_splat_offset(<4 x b32> %x) { +; CHECK-LABEL: define <4 x i8> @neg_bitextract_vec_non_splat_offset( +; CHECK-SAME: <4 x b32> [[X:%.*]]) { +; CHECK-NEXT: [[R:%.*]] = bitextract <4 x i8>, <4 x b32> [[X]], <4 x i32> <i32 0, i32 8, i32 16, i32 25> +; CHECK-NEXT: ret <4 x i8> [[R]] +; + %r = bitextract <4 x i8>, <4 x b32> %x, <4 x i32> <i32 0, i32 8, i32 16, i32 25> + ret <4 x i8> %r +} + define <vscale x 4 x i8> @bitextract_scalable_vec_out_of_range(<vscale x 4 x b32> %x) { ; CHECK-LABEL: define <vscale x 4 x i8> @bitextract_scalable_vec_out_of_range( ; CHECK-SAME: <vscale x 4 x b32> [[X:%.*]]) { @@ -303,3 +334,112 @@ define <vscale x 4 x i8> @bitextract_scalable_vec_out_of_range(<vscale x 4 x b32 %r = bitextract <vscale x 4 x i8>, <vscale x 4 x b32> %x, <vscale x 4 x i32> splat (i32 25) ret <vscale x 4 x i8> %r } + +define <4 x b32> @bitinsert_vec_out_of_range(<4 x b32> %x, <4 x i8> %y) { +; CHECK-LABEL: define <4 x b32> @bitinsert_vec_out_of_range( +; CHECK-SAME: <4 x b32> [[X:%.*]], <4 x i8> [[Y:%.*]]) { +; CHECK-NEXT: ret <4 x b32> poison +; + %r = bitinsert <4 x b32> %x, <4 x i8> %y, <4 x i32> splat (i32 25) + ret <4 x b32> %r +} + +; The last bits of each element are in range. +define <4 x b32> @neg_bitinsert_vec_in_range(<4 x b32> %x, <4 x i8> %y) { +; CHECK-LABEL: define <4 x b32> @neg_bitinsert_vec_in_range( +; CHECK-SAME: <4 x b32> [[X:%.*]], <4 x i8> [[Y:%.*]]) { +; CHECK-NEXT: [[R:%.*]] = bitinsert <4 x b32> [[X]], <4 x i8> [[Y]], <4 x i32> splat (i32 24) +; CHECK-NEXT: ret <4 x b32> [[R]] +; + %r = bitinsert <4 x b32> %x, <4 x i8> %y, <4 x i32> splat (i32 24) + ret <4 x b32> %r +} + +; Only the last lane is out of range. +define <4 x b32> @neg_bitinsert_vec_non_splat_offset(<4 x b32> %x, <4 x i8> %y) { +; CHECK-LABEL: define <4 x b32> @neg_bitinsert_vec_non_splat_offset( +; CHECK-SAME: <4 x b32> [[X:%.*]], <4 x i8> [[Y:%.*]]) { +; CHECK-NEXT: [[R:%.*]] = bitinsert <4 x b32> [[X]], <4 x i8> [[Y]], <4 x i32> <i32 0, i32 8, i32 16, i32 25> +; CHECK-NEXT: ret <4 x b32> [[R]] +; + %r = bitinsert <4 x b32> %x, <4 x i8> %y, <4 x i32> <i32 0, i32 8, i32 16, i32 25> + ret <4 x b32> %r +} + +define <4 x i8> @bitextract_vec_poison_offset(<4 x b32> %x) { +; CHECK-LABEL: define <4 x i8> @bitextract_vec_poison_offset( +; CHECK-SAME: <4 x b32> [[X:%.*]]) { +; CHECK-NEXT: ret <4 x i8> poison +; + %r = bitextract <4 x i8>, <4 x b32> %x, <4 x i32> poison + ret <4 x i8> %r +} + +define <4 x b32> @bitinsert_vec_poison_offset(<4 x b32> %x, <4 x i8> %y) { +; CHECK-LABEL: define <4 x b32> @bitinsert_vec_poison_offset( +; CHECK-SAME: <4 x b32> [[X:%.*]], <4 x i8> [[Y:%.*]]) { +; CHECK-NEXT: ret <4 x b32> poison +; + %r = bitinsert <4 x b32> %x, <4 x i8> %y, <4 x i32> poison + ret <4 x b32> %r +} + +; Only the last lane is poison. +define <4 x i8> @neg_bitextract_vec_partial_poison_offset(<4 x b32> %x) { +; CHECK-LABEL: define <4 x i8> @neg_bitextract_vec_partial_poison_offset( +; CHECK-SAME: <4 x b32> [[X:%.*]]) { +; CHECK-NEXT: [[R:%.*]] = bitextract <4 x i8>, <4 x b32> [[X]], <4 x i32> <i32 0, i32 8, i32 16, i32 poison> +; CHECK-NEXT: ret <4 x i8> [[R]] +; + %r = bitextract <4 x i8>, <4 x b32> %x, <4 x i32> <i32 0, i32 8, i32 16, i32 poison> + ret <4 x i8> %r +} + +; Only the last lane is poison. +define <4 x b32> @neg_bitinsert_vec_partial_poison_offset(<4 x b32> %x, <4 x i8> %y) { +; CHECK-LABEL: define <4 x b32> @neg_bitinsert_vec_partial_poison_offset( +; CHECK-SAME: <4 x b32> [[X:%.*]], <4 x i8> [[Y:%.*]]) { +; CHECK-NEXT: [[R:%.*]] = bitinsert <4 x b32> [[X]], <4 x i8> [[Y]], <4 x i32> <i32 0, i32 8, i32 16, i32 poison> +; CHECK-NEXT: ret <4 x b32> [[R]] +; + %r = bitinsert <4 x b32> %x, <4 x i8> %y, <4 x i32> <i32 0, i32 8, i32 16, i32 poison> + ret <4 x b32> %r +} + +define <4 x b32> @bitextract_vec_full_width(<4 x b32> %x, <4 x i32> %n) { +; CHECK-LABEL: define <4 x b32> @bitextract_vec_full_width( +; CHECK-SAME: <4 x b32> [[X:%.*]], <4 x i32> [[N:%.*]]) { +; CHECK-NEXT: ret <4 x b32> [[X]] +; + %r = bitextract <4 x b32>, <4 x b32> %x, <4 x i32> %n + ret <4 x b32> %r +} + +define <4 x b32> @bitinsert_vec_full_width(<4 x b32> %x, <4 x b32> %y, <4 x i32> %n) { +; CHECK-LABEL: define <4 x b32> @bitinsert_vec_full_width( +; CHECK-SAME: <4 x b32> [[X:%.*]], <4 x b32> [[Y:%.*]], <4 x i32> [[N:%.*]]) { +; CHECK-NEXT: ret <4 x b32> [[Y]] +; + %r = bitinsert <4 x b32> %x, <4 x b32> %y, <4 x i32> %n + ret <4 x b32> %r +} + +define <4 x i8> @bitextract_bitinsert_vec(<4 x b32> %x, <4 x i8> %y, <4 x i32> %n) { +; CHECK-LABEL: define <4 x i8> @bitextract_bitinsert_vec( +; CHECK-SAME: <4 x b32> [[X:%.*]], <4 x i8> [[Y:%.*]], <4 x i32> [[N:%.*]]) { +; CHECK-NEXT: ret <4 x i8> [[Y]] +; + %i = bitinsert <4 x b32> %x, <4 x i8> %y, <4 x i32> %n + %r = bitextract <4 x i8>, <4 x b32> %i, <4 x i32> %n + ret <4 x i8> %r +} + +define <4 x b32> @bitinsert_bitextract_vec(<4 x b32> %x, <4 x i32> %n) { +; CHECK-LABEL: define <4 x b32> @bitinsert_bitextract_vec( +; CHECK-SAME: <4 x b32> [[X:%.*]], <4 x i32> [[N:%.*]]) { +; CHECK-NEXT: ret <4 x b32> [[X]] +; + %e = bitextract <4 x i8>, <4 x b32> %x, <4 x i32> %n + %r = bitinsert <4 x b32> %x, <4 x i8> %e, <4 x i32> %n + ret <4 x b32> %r +} `````````` </details> https://github.com/llvm/llvm-project/pull/240197 _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
