[llvm] r338038 - [InstCombine] add tests for udiv with common factor; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 26 09:14:53 PDT 2018
Author: spatel
Date: Thu Jul 26 09:14:53 2018
New Revision: 338038
URL: http://llvm.org/viewvc/llvm-project?rev=338038&view=rev
Log:
[InstCombine] add tests for udiv with common factor; NFC
This fold is mentioned in PR38239:
https://bugs.llvm.org/show_bug.cgi?id=38239
The general case probably belongs in -reassociate, but given that we do
basic reassociation optimizations similar to this in instcombine already,
we might as well be consistent within instcombine and handle this pattern?
Modified:
llvm/trunk/test/Transforms/InstCombine/div.ll
Modified: llvm/trunk/test/Transforms/InstCombine/div.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/div.ll?rev=338038&r1=338037&r2=338038&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/div.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/div.ll Thu Jul 26 09:14:53 2018
@@ -686,3 +686,85 @@ define <2 x i8> @div_factor_unsigned_vec
ret <2 x i8> %r
}
+define i8 @udiv_common_factor(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @udiv_common_factor(
+; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[Z:%.*]], [[X:%.*]]
+; CHECK-NEXT: [[B:%.*]] = mul nuw i8 [[Z]], [[Y:%.*]]
+; CHECK-NEXT: [[C:%.*]] = udiv i8 [[A]], [[B]]
+; CHECK-NEXT: ret i8 [[C]]
+;
+ %a = mul nuw i8 %z, %x
+ %b = mul nuw i8 %z, %y
+ %c = udiv i8 %a, %b
+ ret i8 %c
+}
+
+define <2 x i8> @udiv_common_factor_commute1_vec(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) {
+; CHECK-LABEL: @udiv_common_factor_commute1_vec(
+; CHECK-NEXT: [[A:%.*]] = mul nuw <2 x i8> [[X:%.*]], [[Z:%.*]]
+; CHECK-NEXT: [[B:%.*]] = mul nuw <2 x i8> [[Z]], [[Y:%.*]]
+; CHECK-NEXT: [[C:%.*]] = udiv <2 x i8> [[A]], [[B]]
+; CHECK-NEXT: ret <2 x i8> [[C]]
+;
+ %a = mul nuw <2 x i8> %x, %z
+ %b = mul nuw <2 x i8> %z, %y
+ %c = udiv <2 x i8> %a, %b
+ ret <2 x i8> %c
+}
+
+define i8 @udiv_common_factor_commute2(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @udiv_common_factor_commute2(
+; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], [[Z:%.*]]
+; CHECK-NEXT: [[B:%.*]] = mul nuw i8 [[Y:%.*]], [[Z]]
+; CHECK-NEXT: [[C:%.*]] = udiv i8 [[A]], [[B]]
+; CHECK-NEXT: ret i8 [[C]]
+;
+ %a = mul nuw i8 %x, %z
+ %b = mul nuw i8 %y, %z
+ %c = udiv i8 %a, %b
+ ret i8 %c
+}
+
+define i8 @udiv_common_factor_commute3(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @udiv_common_factor_commute3(
+; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[Z:%.*]], [[X:%.*]]
+; CHECK-NEXT: [[B:%.*]] = mul nuw i8 [[Y:%.*]], [[Z]]
+; CHECK-NEXT: [[C:%.*]] = udiv i8 [[A]], [[B]]
+; CHECK-NEXT: ret i8 [[C]]
+;
+ %a = mul nuw i8 %z, %x
+ %b = mul nuw i8 %y, %z
+ %c = udiv i8 %a, %b
+ ret i8 %c
+}
+
+; Negative test: both mul must be 'nuw'.
+
+define i8 @udiv_common_factor_not_nuw(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @udiv_common_factor_not_nuw(
+; CHECK-NEXT: [[A:%.*]] = mul i8 [[Z:%.*]], [[X:%.*]]
+; CHECK-NEXT: [[B:%.*]] = mul nuw i8 [[Z]], [[Y:%.*]]
+; CHECK-NEXT: [[C:%.*]] = udiv i8 [[A]], [[B]]
+; CHECK-NEXT: ret i8 [[C]]
+;
+ %a = mul i8 %z, %x
+ %b = mul nuw i8 %z, %y
+ %c = udiv i8 %a, %b
+ ret i8 %c
+}
+
+; Negative test: both mul must be 'nuw'.
+
+define <2 x i8> @udiv_common_factor_not_nuw_vec(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) {
+; CHECK-LABEL: @udiv_common_factor_not_nuw_vec(
+; CHECK-NEXT: [[A:%.*]] = mul nuw <2 x i8> [[Z:%.*]], [[X:%.*]]
+; CHECK-NEXT: [[B:%.*]] = mul <2 x i8> [[Z]], [[Y:%.*]]
+; CHECK-NEXT: [[C:%.*]] = udiv <2 x i8> [[A]], [[B]]
+; CHECK-NEXT: ret <2 x i8> [[C]]
+;
+ %a = mul nuw <2 x i8> %z, %x
+ %b = mul <2 x i8> %z, %y
+ %c = udiv <2 x i8> %a, %b
+ ret <2 x i8> %c
+}
+
More information about the llvm-commits
mailing list