-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[SelectionDAG] Peek through freeze to see XOR #147821
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
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-backend-x86 @llvm/pr-subscribers-llvm-selectiondag Author: AZero13 (AZero13) ChangesIt does not matter if xor is undef or not, because x ^ x is 0, even undef. Full diff: https://github.com/llvm/llvm-project/pull/147821.diff 1 Files Affected:
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 9ffdda28f7899..b10a6cc9a6678 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -10016,8 +10016,15 @@ SDValue DAGCombiner::visitXOR(SDNode *N) {
}
}
+ auto PeekThroughFreeze = [](SDValue N) {
+ if (N->getOpcode() == ISD::FREEZE && N.hasOneUse())
+ return N->getOperand(0);
+ return N;
+ };
+
// fold (xor x, x) -> 0
- if (N0 == N1)
+ // FIXME: Refactor this and sub and other similar operations together.
+ if (PeekThroughFreeze(N0) == PeekThroughFreeze(N1))
return tryFoldToZero(DL, TLI, VT, DAG, LegalOperations);
// fold (xor (shl 1, x), -1) -> (rotl ~1, x)
|
DAG now aggressively pushes freeze up through logic ops, why is this patch necessary? |
In this case the input the XOR is a freeze. We don't know what the input the freeze is. Could the input to the freeze be an operation we don't push up across? |
Well tests say otherwise. |
Ok then I'll write the test https://godbolt.org/z/v65a16W86 or https://godbolt.org/z/aWohvzx3T |
@topperc Okay, it works. |
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
; RUN: llc -mtriple=x86_64-unknown-linux-gnu < %s 2>&1 | FileCheck %s --check-prefix=X86ASM | ||
|
||
define i32 @sub_freeze(i32 %x, i32 %y) { |
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.
please can you put these in freeze-binary.ll
; X86ASM-NEXT: retq | ||
%a = add nuw i32 %x, %y | ||
%b = freeze i32 %a | ||
%c = sub i32 %a, %b |
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.
It does not matter if xor is undef or not, because x ^ x is 0, even undef.
Yes this is more of a change that aligns with x ^ x being 0 even if undef.