[llvm] r352515 - [InstCombine] add tests for ext-of-bool + add/sub; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 29 08:39:23 PST 2019
Author: spatel
Date: Tue Jan 29 08:39:23 2019
New Revision: 352515
URL: http://llvm.org/viewvc/llvm-project?rev=352515&view=rev
Log:
[InstCombine] add tests for ext-of-bool + add/sub; NFC
We should choose one of these as canonical:
%z = zext i1 %cmp to i32
%r = sub i32 %x, %z
=>
%s = sext i1 %cmp to i32
%r = add i32 %x, %s
The test comments assume that the zext form is better,
but we can adjust that if we decide to go the other way.
Modified:
llvm/trunk/test/Transforms/InstCombine/zext-bool-add-sub.ll
Modified: llvm/trunk/test/Transforms/InstCombine/zext-bool-add-sub.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/zext-bool-add-sub.ll?rev=352515&r1=352514&r2=352515&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/zext-bool-add-sub.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/zext-bool-add-sub.ll Tue Jan 29 08:39:23 2019
@@ -315,3 +315,90 @@ define i8 @sext_sub_nuw(i8 %x, i1 %y) {
ret i8 %sub
}
+define i32 @sextbool_add(i1 %c, i32 %x) {
+; CHECK-LABEL: @sextbool_add(
+; CHECK-NEXT: [[B:%.*]] = sext i1 [[C:%.*]] to i32
+; CHECK-NEXT: [[S:%.*]] = add i32 [[B]], [[X:%.*]]
+; CHECK-NEXT: ret i32 [[S]]
+;
+ %b = sext i1 %c to i32
+ %s = add i32 %b, %x
+ ret i32 %s
+}
+
+define i32 @sextbool_add_commute(i1 %c, i32 %px) {
+; CHECK-LABEL: @sextbool_add_commute(
+; CHECK-NEXT: [[X:%.*]] = urem i32 [[PX:%.*]], 42
+; CHECK-NEXT: [[B:%.*]] = sext i1 [[C:%.*]] to i32
+; CHECK-NEXT: [[S:%.*]] = add nsw i32 [[X]], [[B]]
+; CHECK-NEXT: ret i32 [[S]]
+;
+ %x = urem i32 %px, 42 ; thwart complexity-based canonicalization
+ %b = sext i1 %c to i32
+ %s = add i32 %x, %b
+ ret i32 %s
+}
+
+; Negative test - extra use prevents canonicalization.
+
+declare void @use32(i32)
+
+define i32 @sextbool_add_uses(i1 %c, i32 %x) {
+; CHECK-LABEL: @sextbool_add_uses(
+; CHECK-NEXT: [[B:%.*]] = sext i1 [[C:%.*]] to i32
+; CHECK-NEXT: call void @use32(i32 [[B]])
+; CHECK-NEXT: [[S:%.*]] = add i32 [[B]], [[X:%.*]]
+; CHECK-NEXT: ret i32 [[S]]
+;
+ %b = sext i1 %c to i32
+ call void @use32(i32 %b)
+ %s = add i32 %b, %x
+ ret i32 %s
+}
+
+define <4 x i32> @sextbool_add_vector(<4 x i1> %c, <4 x i32> %x) {
+; CHECK-LABEL: @sextbool_add_vector(
+; CHECK-NEXT: [[B:%.*]] = sext <4 x i1> [[C:%.*]] to <4 x i32>
+; CHECK-NEXT: [[S:%.*]] = add <4 x i32> [[B]], [[X:%.*]]
+; CHECK-NEXT: ret <4 x i32> [[S]]
+;
+ %b = sext <4 x i1> %c to <4 x i32>
+ %s = add <4 x i32> %x, %b
+ ret <4 x i32> %s
+}
+
+define i32 @zextbool_sub(i1 %c, i32 %x) {
+; CHECK-LABEL: @zextbool_sub(
+; CHECK-NEXT: [[B:%.*]] = zext i1 [[C:%.*]] to i32
+; CHECK-NEXT: [[S:%.*]] = sub i32 [[B]], [[X:%.*]]
+; CHECK-NEXT: ret i32 [[S]]
+;
+ %b = zext i1 %c to i32
+ %s = sub i32 %b, %x
+ ret i32 %s
+}
+
+define i32 @zextbool_sub_uses(i1 %c, i32 %x) {
+; CHECK-LABEL: @zextbool_sub_uses(
+; CHECK-NEXT: [[B:%.*]] = zext i1 [[C:%.*]] to i32
+; CHECK-NEXT: call void @use32(i32 [[B]])
+; CHECK-NEXT: [[S:%.*]] = sub i32 [[X:%.*]], [[B]]
+; CHECK-NEXT: ret i32 [[S]]
+;
+ %b = zext i1 %c to i32
+ call void @use32(i32 %b)
+ %s = sub i32 %x, %b
+ ret i32 %s
+}
+
+define <4 x i32> @zextbool_sub_vector(<4 x i1> %c, <4 x i32> %x) {
+; CHECK-LABEL: @zextbool_sub_vector(
+; CHECK-NEXT: [[B:%.*]] = zext <4 x i1> [[C:%.*]] to <4 x i32>
+; CHECK-NEXT: [[S:%.*]] = sub <4 x i32> [[X:%.*]], [[B]]
+; CHECK-NEXT: ret <4 x i32> [[S]]
+;
+ %b = zext <4 x i1> %c to <4 x i32>
+ %s = sub <4 x i32> %x, %b
+ ret <4 x i32> %s
+}
+
More information about the llvm-commits
mailing list