[llvm] d4a4004 - [InstCombine] add tests for add of select with 0 and negate arms; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 6 09:20:10 PDT 2022
Author: Sanjay Patel
Date: 2022-09-06T12:19:49-04:00
New Revision: d4a4004c0f9d3070e6c192b9a5bc260bee62e8a8
URL: https://github.com/llvm/llvm-project/commit/d4a4004c0f9d3070e6c192b9a5bc260bee62e8a8
DIFF: https://github.com/llvm/llvm-project/commit/d4a4004c0f9d3070e6c192b9a5bc260bee62e8a8.diff
LOG: [InstCombine] add tests for add of select with 0 and negate arms; NFC
Added:
Modified:
llvm/test/Transforms/InstCombine/add.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/add.ll b/llvm/test/Transforms/InstCombine/add.ll
index 486078cb9b05..01d4319805b4 100644
--- a/llvm/test/Transforms/InstCombine/add.ll
+++ b/llvm/test/Transforms/InstCombine/add.ll
@@ -1960,3 +1960,102 @@ define i8 @full_ashr_not_inc(i8 %x) {
%r = add i8 %a, 2
ret i8 %r
}
+
+define i8 @select_negate_or_zero(i1 %b, i8 %x, i8 %y) {
+; CHECK-LABEL: @select_negate_or_zero(
+; CHECK-NEXT: [[NEGX:%.*]] = sub i8 0, [[X:%.*]]
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[B:%.*]], i8 0, i8 [[NEGX]]
+; CHECK-NEXT: [[ADD:%.*]] = add i8 [[SEL]], [[Y:%.*]]
+; CHECK-NEXT: ret i8 [[ADD]]
+;
+ %negx = sub i8 0, %x
+ %sel = select i1 %b, i8 0, i8 %negx
+ %add = add i8 %sel, %y
+ ret i8 %add
+}
+
+define <2 x i8> @select_negate_or_zero_commute(<2 x i1> %b, <2 x i8> %x, <2 x i8> %p) {
+; CHECK-LABEL: @select_negate_or_zero_commute(
+; CHECK-NEXT: [[Y:%.*]] = mul <2 x i8> [[P:%.*]], [[P]]
+; CHECK-NEXT: [[NEGX:%.*]] = sub <2 x i8> <i8 poison, i8 0>, [[X:%.*]]
+; CHECK-NEXT: [[SEL:%.*]] = select <2 x i1> [[B:%.*]], <2 x i8> <i8 poison, i8 0>, <2 x i8> [[NEGX]]
+; CHECK-NEXT: [[ADD:%.*]] = add <2 x i8> [[Y]], [[SEL]]
+; CHECK-NEXT: ret <2 x i8> [[ADD]]
+;
+ %y = mul <2 x i8> %p, %p ; thwart complexity-based canonicalization
+ %negx = sub <2 x i8> <i8 poison, i8 0>, %x
+ %sel = select <2 x i1> %b, <2 x i8> <i8 poison, i8 0>, <2 x i8> %negx
+ %add = add <2 x i8> %y, %sel
+ ret <2 x i8> %add
+}
+
+define i8 @select_negate_or_zero_swap(i1 %b, i8 %x, i8 %y) {
+; CHECK-LABEL: @select_negate_or_zero_swap(
+; CHECK-NEXT: [[NEGX:%.*]] = sub i8 0, [[X:%.*]]
+; CHECK-NEXT: call void @use(i8 [[NEGX]])
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[B:%.*]], i8 [[NEGX]], i8 0
+; CHECK-NEXT: [[ADD:%.*]] = add i8 [[SEL]], [[Y:%.*]]
+; CHECK-NEXT: ret i8 [[ADD]]
+;
+ %negx = sub i8 0, %x
+ call void @use(i8 %negx)
+ %sel = select i1 %b, i8 %negx, i8 0
+ %add = add i8 %sel, %y
+ ret i8 %add
+}
+
+define i8 @select_negate_or_zero_swap_commute(i1 %b, i8 %x, i8 %p) {
+; CHECK-LABEL: @select_negate_or_zero_swap_commute(
+; CHECK-NEXT: [[Y:%.*]] = mul i8 [[P:%.*]], [[P]]
+; CHECK-NEXT: [[NEGX:%.*]] = sub i8 0, [[X:%.*]]
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[B:%.*]], i8 [[NEGX]], i8 0
+; CHECK-NEXT: [[ADD:%.*]] = add i8 [[Y]], [[SEL]]
+; CHECK-NEXT: ret i8 [[ADD]]
+;
+ %y = mul i8 %p, %p ; thwart complexity-based canonicalization
+ %negx = sub i8 0, %x
+ %sel = select i1 %b, i8 %negx, i8 0
+ %add = add i8 %y, %sel
+ ret i8 %add
+}
+
+define i8 @select_negate_or_nonzero(i1 %b, i8 %x, i8 %y) {
+; CHECK-LABEL: @select_negate_or_nonzero(
+; CHECK-NEXT: [[NEGX:%.*]] = sub i8 0, [[X:%.*]]
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[B:%.*]], i8 42, i8 [[NEGX]]
+; CHECK-NEXT: [[ADD:%.*]] = add i8 [[SEL]], [[Y:%.*]]
+; CHECK-NEXT: ret i8 [[ADD]]
+;
+ %negx = sub i8 0, %x
+ %sel = select i1 %b, i8 42, i8 %negx
+ %add = add i8 %sel, %y
+ ret i8 %add
+}
+
+define i8 @select_nonnegate_or_zero(i1 %b, i8 %x, i8 %y) {
+; CHECK-LABEL: @select_nonnegate_or_zero(
+; CHECK-NEXT: [[NEGX:%.*]] = sub i8 42, [[X:%.*]]
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[B:%.*]], i8 0, i8 [[NEGX]]
+; CHECK-NEXT: [[ADD:%.*]] = add i8 [[SEL]], [[Y:%.*]]
+; CHECK-NEXT: ret i8 [[ADD]]
+;
+ %negx = sub i8 42, %x
+ %sel = select i1 %b, i8 0, i8 %negx
+ %add = add i8 %sel, %y
+ ret i8 %add
+}
+
+define i8 @select_negate_or_nonzero_use(i1 %b, i8 %x, i8 %y) {
+; CHECK-LABEL: @select_negate_or_nonzero_use(
+; CHECK-NEXT: [[NEGX:%.*]] = sub i8 0, [[X:%.*]]
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[B:%.*]], i8 0, i8 [[NEGX]]
+; CHECK-NEXT: call void @use(i8 [[SEL]])
+; CHECK-NEXT: [[ADD:%.*]] = add i8 [[SEL]], [[Y:%.*]]
+; CHECK-NEXT: ret i8 [[ADD]]
+;
+ %negx = sub i8 0, %x
+ %sel = select i1 %b, i8 0, i8 %negx
+ call void @use(i8 %sel)
+ %add = add i8 %sel, %y
+ ret i8 %add
+}
More information about the llvm-commits
mailing list