Skip to content

Commit 49ebe32

Browse files
authored
[X86] combineAndNotOrIntoAndNotAnd - don't fold other constant operands (#113264)
Looks like having a constant in `Z` also caused infinite loops. This fixes #113240.
1 parent 9e3d465 commit 49ebe32

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50049,8 +50049,9 @@ static SDValue combineAndNotOrIntoAndNotAnd(SDNode *N, SelectionDAG &DAG) {
5004950049
SDValue X, Y, Z;
5005050050
if (sd_match(N, m_And(m_Value(X),
5005150051
m_OneUse(m_Or(m_Value(Y), m_Not(m_Value(Z))))))) {
50052-
// Don't fold if Y is a constant to prevent infinite loops.
50053-
if (!isa<ConstantSDNode>(Y))
50052+
// Don't fold if Y or Z are constants to prevent infinite loops.
50053+
if (!DAG.isConstantIntBuildVectorOrConstantInt(Y) &&
50054+
!DAG.isConstantIntBuildVectorOrConstantInt(Z))
5005450055
return DAG.getNode(
5005550056
ISD::AND, DL, VT, X,
5005650057
DAG.getNOT(

llvm/test/CodeGen/X86/pr108731.ll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,23 @@ define void @PR112347(ptr %p0, ptr %p1, ptr %p2) {
192192
ret void
193193
}
194194

195+
define void @PR113240(i64 %a) {
196+
; CHECK-LABEL: PR113240:
197+
; CHECK: # %bb.0: # %entry
198+
; CHECK-NEXT: movq %rdi, %rax
199+
; CHECK-NEXT: notq %rax
200+
; CHECK-NEXT: movabsq $8796093022206, %rcx # imm = 0x7FFFFFFFFFE
201+
; CHECK-NEXT: notq %rcx
202+
; CHECK-NEXT: orq %rax, %rcx
203+
; CHECK-NEXT: andq %rdi, %rcx
204+
; CHECK-NEXT: movq %rcx, 0
205+
; CHECK-NEXT: retq
206+
entry:
207+
%and = and i64 %a, 8796093022206
208+
%bf.value = and i64 8796093022206, 0
209+
%not = xor i64 %and, -1
210+
%and4 = and i64 %a, %not
211+
store i64 %and4, ptr null, align 8
212+
ret void
213+
}
214+

0 commit comments

Comments
 (0)