[llvm] X86: Emit adox instead of adc for overflow add (PR #216609)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 22 13:25:47 PDT 2026
================
@@ -59769,6 +59786,47 @@ static SDValue combineADC(SDNode *N, SelectionDAG &DAG,
return SDValue();
}
+// Optimize RES, EFLAGS = X86ISD::ADOX LHS, RHS, EFLAGS
+static SDValue combineADOX(SDNode *N, SelectionDAG &DAG) {
+ SDValue LHS = N->getOperand(0);
+ SDValue RHS = N->getOperand(1);
+ SDValue CarryIn = N->getOperand(2);
+ auto *LHSC = dyn_cast<ConstantSDNode>(LHS);
+ auto *RHSC = dyn_cast<ConstantSDNode>(RHS);
+
+ // Canonicalize constant to RHS.
+ if (LHSC && !RHSC)
+ return DAG.getNode(X86ISD::ADOX, SDLoc(N), N->getVTList(), RHS, LHS,
+ CarryIn);
+
+ // Fold ADOX(ADD(X,Y),0,Carry) -> ADOX(X,Y,Carry)
+ // ISD::ADD produces no EFLAGS, so we only need to ensure the ADOX's own
+ // flag output is not needed before replacing it with a 2-operand ADOX.
+ SDValue AddOp = LHS;
+
+ // Unwrap extensions. This changes what the wide intermediate represents,
+ // but it is safe because X86ISD::ADOX currently only has one producer
----------------
topperc wrote:
We shouldn't make assumptions like this. This is the kind of thing that's easy to break in the future.
https://github.com/llvm/llvm-project/pull/216609
More information about the llvm-commits
mailing list