diff options
| author | Sanjay Patel <spatel@rotateright.com> | 2019-01-29 16:39:23 +0000 |
|---|---|---|
| committer | Sanjay Patel <spatel@rotateright.com> | 2019-01-29 16:39:23 +0000 |
| commit | f044d1884d9819430906e921490cd62530731fb6 (patch) | |
| tree | 9864baa67be7ac31a48c918011c0fae22e943316 | |
| parent | 5d71fc5d7b5ffe2323418a09db6eddaf84d6c662 (diff) | |
| download | bcm5719-llvm-f044d1884d9819430906e921490cd62530731fb6.tar.gz bcm5719-llvm-f044d1884d9819430906e921490cd62530731fb6.zip | |
[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.
llvm-svn: 352515
| -rw-r--r-- | llvm/test/Transforms/InstCombine/zext-bool-add-sub.ll | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstCombine/zext-bool-add-sub.ll b/llvm/test/Transforms/InstCombine/zext-bool-add-sub.ll index 3fe5bddd117..d009aa9ed97 100644 --- a/llvm/test/Transforms/InstCombine/zext-bool-add-sub.ll +++ b/llvm/test/Transforms/InstCombine/zext-bool-add-sub.ll @@ -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 +} + |

