[llvm] [DAGCombiner] Handle type-promoted constants in UDIV lowering (PR #169491)
David Green via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 1 03:31:58 PST 2025
================
@@ -1076,9 +1077,17 @@ static bool isConstantOrConstantVector(SDValue N, bool NoOpaques = false) {
if (Op.isUndef())
continue;
ConstantSDNode *Const = dyn_cast<ConstantSDNode>(Op);
- if (!Const || Const->getAPIntValue().getBitWidth() != BitWidth ||
- (Const->isOpaque() && NoOpaques))
+ if (!Const || (Const->isOpaque() && NoOpaques))
return false;
+ // When AllowTruncation is true, allow constants that have been promoted
+ // during type legalization as long as the value fits in the target type.
+ if (AllowTruncation) {
+ if (Const->getAPIntValue().getActiveBits() > BitWidth)
+ return false;
+ } else {
+ if (Const->getAPIntValue().getBitWidth() != BitWidth)
+ return false;
+ }
----------------
davemgreen wrote:
```
if ((AllowTruncation && Const->getAPIntValue().getActiveBits() > BitWidth) ||
(!AllowTruncation && Const->getAPIntValue().getActiveBits() != BitWidth))
return false;
```
https://github.com/llvm/llvm-project/pull/169491
More information about the llvm-commits
mailing list