[llvm] bf44905 - [InstCombine] add tests for difference-of-squares; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 17 12:00:59 PST 2023
Author: Sanjay Patel
Date: 2023-01-17T14:58:40-05:00
New Revision: bf44905183efe54599956e308a236635c9b46e71
URL: https://github.com/llvm/llvm-project/commit/bf44905183efe54599956e308a236635c9b46e71
DIFF: https://github.com/llvm/llvm-project/commit/bf44905183efe54599956e308a236635c9b46e71.diff
LOG: [InstCombine] add tests for difference-of-squares; NFC
Added:
Modified:
llvm/test/Transforms/InstCombine/sub.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/sub.ll b/llvm/test/Transforms/InstCombine/sub.ll
index e871b109127c..4a6a1334b170 100644
--- a/llvm/test/Transforms/InstCombine/sub.ll
+++ b/llvm/test/Transforms/InstCombine/sub.ll
@@ -1307,8 +1307,8 @@ define <2 x i32> @test69(<2 x i32> %x) {
; Check (X | Y) - Y --> X & ~Y when Y is a constant
define i32 @test70(i32 %A) {
; CHECK-LABEL: @test70(
-; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], -124
-; CHECK-NEXT: ret i32 [[TMP1]]
+; CHECK-NEXT: [[C:%.*]] = and i32 [[A:%.*]], -124
+; CHECK-NEXT: ret i32 [[C]]
;
%B = or i32 %A, 123
%C = sub i32 %B, 123
@@ -2389,3 +2389,98 @@ define <2 x i8> @sub_to_and_vector4(<2 x i8> %x) {
%r = sub <2 x i8> <i8 88, i8 undef>, %and
ret <2 x i8> %r
}
+
+define i8 @
diff _of_squares(i8 %x, i8 %y) {
+; CHECK-LABEL: @
diff _of_squares(
+; CHECK-NEXT: [[X2:%.*]] = mul i8 [[X:%.*]], [[X]]
+; CHECK-NEXT: [[Y2:%.*]] = mul i8 [[Y:%.*]], [[Y]]
+; CHECK-NEXT: [[R:%.*]] = sub i8 [[X2]], [[Y2]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %x2 = mul i8 %x, %x
+ %y2 = mul i8 %y, %y
+ %r = sub i8 %x2, %y2
+ ret i8 %r
+}
+
+define i5 @
diff _of_squares_nuw(i5 %x, i5 %y) {
+; CHECK-LABEL: @
diff _of_squares_nuw(
+; CHECK-NEXT: [[X2:%.*]] = mul nuw i5 [[X:%.*]], [[X]]
+; CHECK-NEXT: [[Y2:%.*]] = mul nuw i5 [[Y:%.*]], [[Y]]
+; CHECK-NEXT: [[R:%.*]] = sub nuw i5 [[X2]], [[Y2]]
+; CHECK-NEXT: ret i5 [[R]]
+;
+ %x2 = mul nuw i5 %x, %x
+ %y2 = mul nuw i5 %y, %y
+ %r = sub nuw i5 %x2, %y2
+ ret i5 %r
+}
+
+define i5 @
diff _of_squares_partial_nuw(i5 %x, i5 %y) {
+; CHECK-LABEL: @
diff _of_squares_partial_nuw(
+; CHECK-NEXT: [[X2:%.*]] = mul nuw i5 [[X:%.*]], [[X]]
+; CHECK-NEXT: [[Y2:%.*]] = mul nuw i5 [[Y:%.*]], [[Y]]
+; CHECK-NEXT: [[R:%.*]] = sub i5 [[X2]], [[Y2]]
+; CHECK-NEXT: ret i5 [[R]]
+;
+ %x2 = mul nuw i5 %x, %x
+ %y2 = mul nuw i5 %y, %y
+ %r = sub i5 %x2, %y2
+ ret i5 %r
+}
+
+define <2 x i5> @
diff _of_squares_nsw(<2 x i5> %x, <2 x i5> %y) {
+; CHECK-LABEL: @
diff _of_squares_nsw(
+; CHECK-NEXT: [[X2:%.*]] = mul nsw <2 x i5> [[X:%.*]], [[X]]
+; CHECK-NEXT: [[Y2:%.*]] = mul nsw <2 x i5> [[Y:%.*]], [[Y]]
+; CHECK-NEXT: [[R:%.*]] = sub nsw <2 x i5> [[X2]], [[Y2]]
+; CHECK-NEXT: ret <2 x i5> [[R]]
+;
+ %x2 = mul nsw <2 x i5> %x, %x
+ %y2 = mul nsw <2 x i5> %y, %y
+ %r = sub nsw <2 x i5> %x2, %y2
+ ret <2 x i5> %r
+}
+
+define <2 x i5> @
diff _of_squares_partial_nsw(<2 x i5> %x, <2 x i5> %y) {
+; CHECK-LABEL: @
diff _of_squares_partial_nsw(
+; CHECK-NEXT: [[X2:%.*]] = mul nsw <2 x i5> [[X:%.*]], [[X]]
+; CHECK-NEXT: [[Y2:%.*]] = mul <2 x i5> [[Y:%.*]], [[Y]]
+; CHECK-NEXT: [[R:%.*]] = sub nsw <2 x i5> [[X2]], [[Y2]]
+; CHECK-NEXT: ret <2 x i5> [[R]]
+;
+ %x2 = mul nsw <2 x i5> %x, %x
+ %y2 = mul <2 x i5> %y, %y
+ %r = sub nsw <2 x i5> %x2, %y2
+ ret <2 x i5> %r
+}
+
+define i8 @
diff _of_squares_use1(i8 %x, i8 %y) {
+; CHECK-LABEL: @
diff _of_squares_use1(
+; CHECK-NEXT: [[X2:%.*]] = mul i8 [[X:%.*]], [[X]]
+; CHECK-NEXT: call void @use8(i8 [[X2]])
+; CHECK-NEXT: [[Y2:%.*]] = mul i8 [[Y:%.*]], [[Y]]
+; CHECK-NEXT: [[R:%.*]] = sub i8 [[X2]], [[Y2]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %x2 = mul i8 %x, %x
+ call void @use8(i8 %x2)
+ %y2 = mul i8 %y, %y
+ %r = sub i8 %x2, %y2
+ ret i8 %r
+}
+
+define i8 @
diff _of_squares_use2(i8 %x, i8 %y) {
+; CHECK-LABEL: @
diff _of_squares_use2(
+; CHECK-NEXT: [[X2:%.*]] = mul i8 [[X:%.*]], [[X]]
+; CHECK-NEXT: [[Y2:%.*]] = mul i8 [[Y:%.*]], [[Y]]
+; CHECK-NEXT: call void @use8(i8 [[Y2]])
+; CHECK-NEXT: [[R:%.*]] = sub i8 [[X2]], [[Y2]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %x2 = mul i8 %x, %x
+ %y2 = mul i8 %y, %y
+ call void @use8(i8 %y2)
+ %r = sub i8 %x2, %y2
+ ret i8 %r
+}
More information about the llvm-commits
mailing list