[llvm] [DAGCombiner] Fold min/max vscale, C -> C (PR #174708)

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 9 01:30:41 PST 2026


================
@@ -6253,6 +6243,34 @@ SDValue DAGCombiner::visitIMINMAX(SDNode *N) {
                                         SDLoc(N), VT, N0, N1))
     return SD;
 
+  // Fold operation with vscale operands.
+  if (N0.getOpcode() == ISD::VSCALE && N1.getOpcode() == ISD::VSCALE) {
----------------
sdesmalen-arm wrote:

`vscale` if set by `vscale_range` is always known to be non-zero. Could there be something missing in `computeKnownBits`?

> vscale_range(<min>[, <max>])
> This function attribute indicates vscale is a power-of-two within a specified range. min must be a power-of-two that is greater than 0. [...] Functions that don’t include this attribute make no assumptions about the value of vscale.

> It also looks like there isn't a computeConstantRange equivalent for SelectionDAG unfortunately.

KnownBits can compute the known bits of the `mul`, which given information about known zero bits of both the 'vscale' and constant value, should be able to tell something about its range that `ConstantRange::fromKnownBits` could use?

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


More information about the llvm-commits mailing list