[llvm] [SDAG] (abd? (?ext x), c) -> (zext (abd? x, c)) (PR #176366)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 22 07:32:09 PST 2026
================
@@ -5828,6 +5812,34 @@ SDValue DAGCombiner::visitABD(SDNode *N) {
}
}
+ // fold (abd? (?ext ty:x), small_const:c) -> (zext (abd? x, c))
+ if (sd_match(N, m_c_BinOp(ISD::ABDU, m_ZExt(m_Value(X)), m_Value(Y))) ||
+ sd_match(N, m_c_BinOp(ISD::ABDS, m_SExt(m_Value(X)), m_Value(Y)))) {
+ EVT SmallVT = X.getValueType();
+ if (!LegalOperations || hasOperation(Opcode, SmallVT)) {
+ uint64_t Bits = SmallVT.getScalarSizeInBits();
+ unsigned RelevantBits =
+ (Opcode == ISD::ABDS) ? DAG.ComputeMaxSignificantBits(Y)
+ : DAG.computeKnownBits(Y).countMaxActiveBits();
+ bool TruncatingYIsCheap = TLI.isTruncateFree(Y, SmallVT) ||
+ ISD::matchUnaryPredicate(
+ Y,
+ [&](auto *C) {
+ APInt YConst = C->getAsAPIntVal();
----------------
RKSimon wrote:
```suggestion
const APInt &YConst = C->getAsAPIntVal();
```
https://github.com/llvm/llvm-project/pull/176366
More information about the llvm-commits
mailing list