[llvm] [X86] Implement canceling out of XOR with equality (PR #155106)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 23 17:10:08 PDT 2025
================
@@ -49009,6 +49009,28 @@ static SDValue combineSetCCMOVMSK(SDValue EFLAGS, X86::CondCode &CC,
static SDValue combineSetCCEFLAGS(SDValue EFLAGS, X86::CondCode &CC,
SelectionDAG &DAG,
const X86Subtarget &Subtarget) {
+ // For EQ/NE, rewrite SUB(xor A,B, xor C,B) -> SUB(A,C) and
+ // SUB(add A,K, add C,K) -> SUB(A,C)
+ // Only safe if the arithmetic result is unused, since we only
+ // care about flags for EQ/NE.
+
+ // TODO: Can we do this for other comparions like 31 ^ A > 31 ^ B ?
+ if ((CC == X86::COND_E || CC == X86::COND_NE) &&
+ EFLAGS.getOpcode() == X86ISD::SUB &&
+ !EFLAGS.getNode()->hasAnyUseOfValue(0)) {
----------------
arsenm wrote:
```suggestion
!EFLAGS.hasAnyUseOfValue(0)) {
```
https://github.com/llvm/llvm-project/pull/155106
More information about the llvm-commits
mailing list