summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2019-06-23 14:22:37 +0000
committerSanjay Patel <spatel@rotateright.com>2019-06-23 14:22:37 +0000
commit13a5ae58fcf1386256e56d2dc67c783628c3e0f1 (patch)
treeaf126314af5e3b97bab176e2378b26770a004d20 /llvm/test/Transforms
parent6620e3b2f6937c6b862407043aa49a1efb6f19df (diff)
downloadbcm5719-llvm-13a5ae58fcf1386256e56d2dc67c783628c3e0f1.tar.gz
bcm5719-llvm-13a5ae58fcf1386256e56d2dc67c783628c3e0f1.zip
[InstCombine] squash is-power-of-2 that uses ctpop
This is another intermediate IR step towards solving PR42314: https://bugs.llvm.org/show_bug.cgi?id=42314 We can test if a value is power-of-2-or-0 using ctpop(X) < 2, so combining that with a non-zero check of the input is the same as testing if exactly 1 bit is set: (X != 0) && (ctpop(X) u< 2) --> ctpop(X) == 1 Differential Revision: https://reviews.llvm.org/D63660 llvm-svn: 364153
Diffstat (limited to 'llvm/test/Transforms')
-rw-r--r--llvm/test/Transforms/InstCombine/ispow2.ll26
1 files changed, 16 insertions, 10 deletions
diff --git a/llvm/test/Transforms/InstCombine/ispow2.ll b/llvm/test/Transforms/InstCombine/ispow2.ll
index 6ce825be20b..513eb85421d 100644
--- a/llvm/test/Transforms/InstCombine/ispow2.ll
+++ b/llvm/test/Transforms/InstCombine/ispow2.ll
@@ -187,13 +187,13 @@ define i1 @is_pow2or0_negate_op_extra_use2(i32 %x) {
declare i32 @llvm.ctpop.i32(i32)
declare <2 x i8> @llvm.ctpop.v2i8(<2 x i8>)
+; (X != 0) && (ctpop(X) u< 2) --> ctpop(X) == 1
+
define i1 @is_pow2_ctpop(i32 %x) {
; CHECK-LABEL: @is_pow2_ctpop(
; CHECK-NEXT: [[T0:%.*]] = tail call i32 @llvm.ctpop.i32(i32 [[X:%.*]]), !range !0
-; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[T0]], 2
-; CHECK-NEXT: [[NOTZERO:%.*]] = icmp ne i32 [[X]], 0
-; CHECK-NEXT: [[R:%.*]] = and i1 [[NOTZERO]], [[CMP]]
-; CHECK-NEXT: ret i1 [[R]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[T0]], 1
+; CHECK-NEXT: ret i1 [[TMP1]]
;
%t0 = tail call i32 @llvm.ctpop.i32(i32 %x)
%cmp = icmp ult i32 %t0, 2
@@ -212,8 +212,8 @@ define i1 @is_pow2_ctpop_extra_uses(i32 %x) {
; CHECK-NEXT: call void @use_i1(i1 [[CMP]])
; CHECK-NEXT: [[NOTZERO:%.*]] = icmp ne i32 [[X]], 0
; CHECK-NEXT: call void @use_i1(i1 [[NOTZERO]])
-; CHECK-NEXT: [[R:%.*]] = and i1 [[NOTZERO]], [[CMP]]
-; CHECK-NEXT: ret i1 [[R]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[T0]], 1
+; CHECK-NEXT: ret i1 [[TMP1]]
;
%t0 = tail call i32 @llvm.ctpop.i32(i32 %x)
%cmp = icmp ult i32 %t0, 2
@@ -229,10 +229,8 @@ define i1 @is_pow2_ctpop_extra_uses(i32 %x) {
define <2 x i1> @is_pow2_ctpop_commute_vec(<2 x i8> %x) {
; CHECK-LABEL: @is_pow2_ctpop_commute_vec(
; CHECK-NEXT: [[T0:%.*]] = tail call <2 x i8> @llvm.ctpop.v2i8(<2 x i8> [[X:%.*]])
-; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i8> [[T0]], <i8 2, i8 2>
-; CHECK-NEXT: [[NOTZERO:%.*]] = icmp ne <2 x i8> [[X]], zeroinitializer
-; CHECK-NEXT: [[R:%.*]] = and <2 x i1> [[CMP]], [[NOTZERO]]
-; CHECK-NEXT: ret <2 x i1> [[R]]
+; CHECK-NEXT: [[TMP1:%.*]] = icmp eq <2 x i8> [[T0]], <i8 1, i8 1>
+; CHECK-NEXT: ret <2 x i1> [[TMP1]]
;
%t0 = tail call <2 x i8> @llvm.ctpop.v2i8(<2 x i8> %x)
%cmp = icmp ult <2 x i8> %t0, <i8 2, i8 2>
@@ -241,6 +239,8 @@ define <2 x i1> @is_pow2_ctpop_commute_vec(<2 x i8> %x) {
ret <2 x i1> %r
}
+; Negative test - wrong constant.
+
define i1 @is_pow2_ctpop_wrong_cmp_op1(i32 %x) {
; CHECK-LABEL: @is_pow2_ctpop_wrong_cmp_op1(
; CHECK-NEXT: [[T0:%.*]] = tail call i32 @llvm.ctpop.i32(i32 [[X:%.*]]), !range !0
@@ -256,6 +256,8 @@ define i1 @is_pow2_ctpop_wrong_cmp_op1(i32 %x) {
ret i1 %r
}
+; Negative test - wrong constant.
+
define i1 @is_pow2_ctpop_wrong_cmp_op2(i32 %x) {
; CHECK-LABEL: @is_pow2_ctpop_wrong_cmp_op2(
; CHECK-NEXT: [[T0:%.*]] = tail call i32 @llvm.ctpop.i32(i32 [[X:%.*]]), !range !0
@@ -271,6 +273,8 @@ define i1 @is_pow2_ctpop_wrong_cmp_op2(i32 %x) {
ret i1 %r
}
+; Negative test - wrong predicate.
+
define i1 @is_pow2_ctpop_wrong_pred1(i32 %x) {
; CHECK-LABEL: @is_pow2_ctpop_wrong_pred1(
; CHECK-NEXT: [[T0:%.*]] = tail call i32 @llvm.ctpop.i32(i32 [[X:%.*]]), !range !0
@@ -286,6 +290,8 @@ define i1 @is_pow2_ctpop_wrong_pred1(i32 %x) {
ret i1 %r
}
+; Negative test - wrong predicate.
+
define i1 @is_pow2_ctpop_wrong_pred2(i32 %x) {
; CHECK-LABEL: @is_pow2_ctpop_wrong_pred2(
; CHECK-NEXT: [[T0:%.*]] = tail call i32 @llvm.ctpop.i32(i32 [[X:%.*]]), !range !0
OpenPOWER on IntegriCloud