[PATCH] D154806: [InstCombine] Add tests for transforming `(add (shl (neg X), Cnt))`; NFC
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 25 20:21:39 PDT 2023
goldstein.w.n updated this revision to Diff 544188.
goldstein.w.n added a comment.
Add second multiuse test
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154806/new/
https://reviews.llvm.org/D154806
Files:
llvm/test/Transforms/InstCombine/add-shift.ll
Index: llvm/test/Transforms/InstCombine/add-shift.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/InstCombine/add-shift.ll
@@ -0,0 +1,82 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+define i8 @flip_add_of_shift_neg(i8 %v, i8 %sh, i8 %x) {
+; CHECK-LABEL: define i8 @flip_add_of_shift_neg
+; CHECK-SAME: (i8 [[V:%.*]], i8 [[SH:%.*]], i8 [[X:%.*]]) {
+; CHECK-NEXT: [[NV:%.*]] = sub i8 0, [[V]]
+; CHECK-NEXT: [[SV:%.*]] = shl nuw nsw i8 [[NV]], [[SH]]
+; CHECK-NEXT: [[R:%.*]] = add i8 [[SV]], [[X]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %nv = sub i8 0, %v
+ %sv = shl nuw nsw i8 %nv, %sh
+ %r = add i8 %sv, %x
+ ret i8 %r
+}
+
+define <2 x i8> @flip_add_of_shift_neg_vec(<2 x i8> %v, <2 x i8> %sh, <2 x i8> %xx) {
+; CHECK-LABEL: define <2 x i8> @flip_add_of_shift_neg_vec
+; CHECK-SAME: (<2 x i8> [[V:%.*]], <2 x i8> [[SH:%.*]], <2 x i8> [[XX:%.*]]) {
+; CHECK-NEXT: [[X:%.*]] = mul <2 x i8> [[XX]], [[XX]]
+; CHECK-NEXT: [[NV:%.*]] = sub <2 x i8> zeroinitializer, [[V]]
+; CHECK-NEXT: [[SV:%.*]] = shl <2 x i8> [[NV]], [[SH]]
+; CHECK-NEXT: [[R:%.*]] = add <2 x i8> [[X]], [[SV]]
+; CHECK-NEXT: ret <2 x i8> [[R]]
+;
+ %x = mul <2 x i8> %xx, %xx
+ %nv = sub <2 x i8> zeroinitializer, %v
+ %sv = shl <2 x i8> %nv, %sh
+ %r = add <2 x i8> %x, %sv
+ ret <2 x i8> %r
+}
+
+define i8 @flip_add_of_shift_neg_fail_shr(i8 %v, i8 %sh, i8 %x) {
+; CHECK-LABEL: define i8 @flip_add_of_shift_neg_fail_shr
+; CHECK-SAME: (i8 [[V:%.*]], i8 [[SH:%.*]], i8 [[X:%.*]]) {
+; CHECK-NEXT: [[NV:%.*]] = sub i8 0, [[V]]
+; CHECK-NEXT: [[SV:%.*]] = lshr i8 [[NV]], [[SH]]
+; CHECK-NEXT: [[R:%.*]] = add i8 [[SV]], [[X]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %nv = sub i8 0, %v
+ %sv = lshr i8 %nv, %sh
+ %r = add i8 %sv, %x
+ ret i8 %r
+}
+
+declare void @use.v2i8(<2 x i8>)
+define <2 x i8> @flip_add_of_shift_neg_vec_fail_multiuse_neg(<2 x i8> %v, <2 x i8> %sh, <2 x i8> %xx) {
+; CHECK-LABEL: define <2 x i8> @flip_add_of_shift_neg_vec_fail_multiuse_neg
+; CHECK-SAME: (<2 x i8> [[V:%.*]], <2 x i8> [[SH:%.*]], <2 x i8> [[XX:%.*]]) {
+; CHECK-NEXT: [[X:%.*]] = mul <2 x i8> [[XX]], [[XX]]
+; CHECK-NEXT: [[NV:%.*]] = sub <2 x i8> zeroinitializer, [[V]]
+; CHECK-NEXT: [[SV:%.*]] = shl <2 x i8> [[NV]], [[SH]]
+; CHECK-NEXT: call void @use.v2i8(<2 x i8> [[NV]])
+; CHECK-NEXT: [[R:%.*]] = add <2 x i8> [[X]], [[SV]]
+; CHECK-NEXT: ret <2 x i8> [[R]]
+;
+ %x = mul <2 x i8> %xx, %xx
+ %nv = sub <2 x i8> zeroinitializer, %v
+ %sv = shl <2 x i8> %nv, %sh
+ call void @use.v2i8(<2 x i8> %nv)
+ %r = add <2 x i8> %x, %sv
+ ret <2 x i8> %r
+}
+
+define <2 x i8> @flip_add_of_shift_neg_vec_fail_multiuse_shift(<2 x i8> %v, <2 x i8> %sh, <2 x i8> %xx) {
+; CHECK-LABEL: define <2 x i8> @flip_add_of_shift_neg_vec_fail_multiuse_shift
+; CHECK-SAME: (<2 x i8> [[V:%.*]], <2 x i8> [[SH:%.*]], <2 x i8> [[XX:%.*]]) {
+; CHECK-NEXT: [[X:%.*]] = mul <2 x i8> [[XX]], [[XX]]
+; CHECK-NEXT: [[NV:%.*]] = sub <2 x i8> zeroinitializer, [[V]]
+; CHECK-NEXT: [[SV:%.*]] = shl <2 x i8> [[NV]], [[SH]]
+; CHECK-NEXT: call void @use.v2i8(<2 x i8> [[SV]])
+; CHECK-NEXT: [[R:%.*]] = add <2 x i8> [[X]], [[SV]]
+; CHECK-NEXT: ret <2 x i8> [[R]]
+;
+ %x = mul <2 x i8> %xx, %xx
+ %nv = sub <2 x i8> zeroinitializer, %v
+ %sv = shl <2 x i8> %nv, %sh
+ call void @use.v2i8(<2 x i8> %sv)
+ %r = add <2 x i8> %x, %sv
+ ret <2 x i8> %r
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154806.544188.patch
Type: text/x-patch
Size: 3553 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230726/29f9f787/attachment.bin>
More information about the llvm-commits
mailing list