Skip to content

Commit c8481f2

Browse files
committed
Revert "[InstCombine] canonicalize zext-and-of-bool compare to narrow and"
This reverts commit b5a9361.
1 parent 6537238 commit c8481f2

File tree

3 files changed

+14
-31
lines changed

3 files changed

+14
-31
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,20 +1947,6 @@ Instruction *InstCombinerImpl::foldICmpAndConstant(ICmpInst &Cmp,
19471947
}
19481948
}
19491949

1950-
// ((zext i1 X) & Y) == 0 --> !((trunc Y) & X)
1951-
// ((zext i1 X) & Y) != 0 --> ((trunc Y) & X)
1952-
// ((zext i1 X) & Y) == 1 --> ((trunc Y) & X)
1953-
// ((zext i1 X) & Y) != 1 --> !((trunc Y) & X)
1954-
if (match(And, m_OneUse(m_c_And(m_OneUse(m_ZExt(m_Value(X))), m_Value(Y)))) &&
1955-
X->getType()->isIntOrIntVectorTy(1) && (C.isZero() || C.isOne())) {
1956-
Value *TruncY = Builder.CreateTrunc(Y, X->getType());
1957-
if (C.isZero() ^ (Pred == CmpInst::ICMP_NE)) {
1958-
Value *And = Builder.CreateAnd(TruncY, X);
1959-
return BinaryOperator::CreateNot(And);
1960-
}
1961-
return BinaryOperator::CreateAnd(TruncY, X);
1962-
}
1963-
19641950
// (icmp eq/ne (and (shl -1, X), Y), 0)
19651951
// -> (icmp eq/ne (lshr Y, X), 0)
19661952
// We could technically handle any C == 0 or (C < 0 && isOdd(C)) but it seems

llvm/test/Transforms/InstCombine/and-xor-or.ll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4342,7 +4342,11 @@ define i32 @or_sext_sext_use1(i8 %x, i4 %y) {
43424342
define i1 @PR56294(i8 %x) {
43434343
; CHECK-LABEL: define {{[^@]+}}@PR56294
43444344
; CHECK-SAME: (i8 [[X:%.*]]) {
4345-
; CHECK-NEXT: ret i1 false
4345+
; CHECK-NEXT: [[T2:%.*]] = icmp eq i8 [[X]], 2
4346+
; CHECK-NEXT: [[TMP1:%.*]] = zext i1 [[T2]] to i8
4347+
; CHECK-NEXT: [[TMP2:%.*]] = and i8 [[TMP1]], [[X]]
4348+
; CHECK-NEXT: [[T7:%.*]] = icmp ne i8 [[TMP2]], 0
4349+
; CHECK-NEXT: ret i1 [[T7]]
43464350
;
43474351
%t2 = icmp eq i8 %x, 2
43484352
%t3 = and i8 %x, 1

llvm/test/Transforms/InstCombine/icmp.ll

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4584,10 +4584,9 @@ define i1 @redundant_sign_bit_count_ugt_31_30(i32 %x) {
45844584

45854585
define i1 @zext_bool_and_eq0(i1 %x, i8 %y) {
45864586
; CHECK-LABEL: @zext_bool_and_eq0(
4587-
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[Y:%.*]], 1
4588-
; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i8 [[TMP1]], 0
4589-
; CHECK-NEXT: [[TMP3:%.*]] = and i1 [[TMP2]], [[X:%.*]]
4590-
; CHECK-NEXT: [[R:%.*]] = xor i1 [[TMP3]], true
4587+
; CHECK-NEXT: [[ZX:%.*]] = zext i1 [[X:%.*]] to i8
4588+
; CHECK-NEXT: [[A:%.*]] = and i8 [[ZX]], [[Y:%.*]]
4589+
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[A]], 0
45914590
; CHECK-NEXT: ret i1 [[R]]
45924591
;
45934592
%zx = zext i1 %x to i8
@@ -4598,9 +4597,9 @@ define i1 @zext_bool_and_eq0(i1 %x, i8 %y) {
45984597

45994598
define <2 x i1> @zext_bool_and_eq0_commute(<2 x i1> %x, <2 x i8> %p) {
46004599
; CHECK-LABEL: @zext_bool_and_eq0_commute(
4601-
; CHECK-NEXT: [[TMP1:%.*]] = trunc <2 x i8> [[P:%.*]] to <2 x i1>
4602-
; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i1> [[TMP1]], [[X:%.*]]
4603-
; CHECK-NEXT: [[R:%.*]] = xor <2 x i1> [[TMP2]], <i1 true, i1 true>
4600+
; CHECK-NEXT: [[ZX:%.*]] = zext <2 x i1> [[X:%.*]] to <2 x i8>
4601+
; CHECK-NEXT: [[A:%.*]] = and <2 x i8> [[ZX]], [[P:%.*]]
4602+
; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i8> [[A]], zeroinitializer
46044603
; CHECK-NEXT: ret <2 x i1> [[R]]
46054604
;
46064605
%y = mul <2 x i8> %p, %p ; thwart complexity-based canonicalization
@@ -4612,9 +4611,9 @@ define <2 x i1> @zext_bool_and_eq0_commute(<2 x i1> %x, <2 x i8> %p) {
46124611

46134612
define i1 @zext_bool_and_ne0(i1 %x, i8 %y) {
46144613
; CHECK-LABEL: @zext_bool_and_ne0(
4615-
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[Y:%.*]], 1
4616-
; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i8 [[TMP1]], 0
4617-
; CHECK-NEXT: [[R:%.*]] = and i1 [[TMP2]], [[X:%.*]]
4614+
; CHECK-NEXT: [[ZX:%.*]] = zext i1 [[X:%.*]] to i8
4615+
; CHECK-NEXT: [[A:%.*]] = and i8 [[ZX]], [[Y:%.*]]
4616+
; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[A]], 0
46184617
; CHECK-NEXT: ret i1 [[R]]
46194618
;
46204619
%zx = zext i1 %x to i8
@@ -4664,8 +4663,6 @@ define i1 @zext_bool_or_eq0(i1 %x, i8 %y) {
46644663
ret i1 %r
46654664
}
46664665

4667-
; negative test - extra use
4668-
46694666
define i1 @zext_bool_and_eq0_use(i1 %x, i64 %y) {
46704667
; CHECK-LABEL: @zext_bool_and_eq0_use(
46714668
; CHECK-NEXT: [[ZX:%.*]] = zext i1 [[X:%.*]] to i64
@@ -4681,8 +4678,6 @@ define i1 @zext_bool_and_eq0_use(i1 %x, i64 %y) {
46814678
ret i1 %r
46824679
}
46834680

4684-
; negative test - extra use
4685-
46864681
define i1 @zext_bool_and_ne0_use(i1 %x, i64 %y) {
46874682
; CHECK-LABEL: @zext_bool_and_ne0_use(
46884683
; CHECK-NEXT: [[ZX:%.*]] = zext i1 [[X:%.*]] to i64
@@ -4698,8 +4693,6 @@ define i1 @zext_bool_and_ne0_use(i1 %x, i64 %y) {
46984693
ret i1 %r
46994694
}
47004695

4701-
; negative test - must zext from i1
4702-
47034696
define i1 @zext_notbool_and_ne0(i2 %x, i8 %y) {
47044697
; CHECK-LABEL: @zext_notbool_and_ne0(
47054698
; CHECK-NEXT: [[ZX:%.*]] = zext i2 [[X:%.*]] to i8

0 commit comments

Comments
 (0)