[llvm] [DAG] Add legalization handling for AVGCEIL/AVGFLOOR nodes (PR #92096)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu May 23 05:30:02 PDT 2024


================
@@ -4560,8 +4560,15 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
     Tmp = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth + 1);
     // SRA X, C -> adds C sign bits.
     if (const APInt *ShAmt =
-            getValidMinimumShiftAmountConstant(Op, DemandedElts))
+            getValidMinimumShiftAmountConstant(Op, DemandedElts)) {
       Tmp = std::min<uint64_t>(Tmp + ShAmt->getZExtValue(), VTBits);
+    } else {
+      KnownBits KnownAmt =
+          computeKnownBits(Op.getOperand(1), DemandedElts, Depth + 1);
+      if (KnownAmt.isConstant() && KnownAmt.getConstant().ult(VTBits))
+        Tmp = std::min<uint64_t>(Tmp + KnownAmt.getConstant().getZExtValue(),
+                                 VTBits);
+    }
----------------
RKSimon wrote:

I've created #93182 as a possible cleanup for this (the pull requests are independent though so we can go with the above approach for now). #93182 should get analyzed up by [llvm-compile-time-tracker](https://llvm-compile-time-tracker.com/?config=Overview&stat=instructions%3Au&remote=RKSimon) in the next hour or so.

https://github.com/llvm/llvm-project/pull/92096


More information about the llvm-commits mailing list