-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[X86] combineAndNotOrIntoAndNotAnd - don't fold other constant operands #113264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-backend-x86 Author: Miguel Saldivar (Saldivarcher) ChangesFull diff: https://github.com/llvm/llvm-project/pull/113264.diff 2 Files Affected:
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index bcb84add65d83e..5ae5a7dbe0f6da 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -50049,8 +50049,8 @@ static SDValue combineAndNotOrIntoAndNotAnd(SDNode *N, SelectionDAG &DAG) {
SDValue X, Y, Z;
if (sd_match(N, m_And(m_Value(X),
m_OneUse(m_Or(m_Value(Y), m_Not(m_Value(Z))))))) {
- // Don't fold if Y is a constant to prevent infinite loops.
- if (!isa<ConstantSDNode>(Y))
+ // Don't fold if Y and Z are constants to prevent infinite loops.
+ if (!isa<ConstantSDNode>(Y) && !isa<ConstantSDNode>(Z))
return DAG.getNode(
ISD::AND, DL, VT, X,
DAG.getNOT(
diff --git a/llvm/test/CodeGen/X86/pr108731.ll b/llvm/test/CodeGen/X86/pr108731.ll
index 473b4f7f4da2e3..2983d108eaeddc 100644
--- a/llvm/test/CodeGen/X86/pr108731.ll
+++ b/llvm/test/CodeGen/X86/pr108731.ll
@@ -192,3 +192,23 @@ define void @PR112347(ptr %p0, ptr %p1, ptr %p2) {
ret void
}
+define void @PR113240(i64 %a) {
+; CHECK-LABEL: PR113240:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: movq %rdi, %rax
+; CHECK-NEXT: notq %rax
+; CHECK-NEXT: movabsq $8796093022206, %rcx # imm = 0x7FFFFFFFFFE
+; CHECK-NEXT: notq %rcx
+; CHECK-NEXT: orq %rax, %rcx
+; CHECK-NEXT: andq %rdi, %rcx
+; CHECK-NEXT: movq %rcx, 0
+; CHECK-NEXT: retq
+entry:
+ %and = and i64 %a, 8796093022206
+ %bf.value = and i64 8796093022206, 0
+ %not = xor i64 %and, -1
+ %and4 = and i64 %a, %not
+ store i64 %and4, ptr null, align 8
+ ret void
+}
+
|
|
@RKSimon let me know what you think. |
|
@phoebewang and @goldsteinn would you be able to review this? @RKSimon might be away. |
|
Sorry, been travelling for the devmtg |
98d2985 to
cb1cc3d
Compare
It's ok, sorry for bugging you! Safe travels btw! |
other constant operands
cb1cc3d to
9182f99
Compare
goldsteinn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, although this type of re-ordering is liable to creating inf loops and this might be the only case. If this continues to be an issue we should probably drop the fold.
|
@goldsteinn would you be able to rebase and merge for me? I don't have write access. I'd be ok with reverting if this keeps causing issues. Thanks for taking a look btw. 👍 |
Looks like having a constant in
Zalso caused infinite loops. This fixes #113240.