[Mlir-commits] [mlir] [mlir][spirv] Implement UMod canonicalization for vector constants (PR #141902)
Igor Wodiany
llvmlistbot at llvm.org
Tue Jun 3 07:29:22 PDT 2025
================
@@ -336,19 +335,28 @@ struct UModSimplification final : OpRewritePattern<spirv::UModOp> {
if (!prevUMod)
return failure();
- IntegerAttr prevValue;
- IntegerAttr currValue;
+ TypedAttr prevValue;
+ TypedAttr currValue;
if (!matchPattern(prevUMod.getOperand(1), m_Constant(&prevValue)) ||
!matchPattern(umodOp.getOperand(1), m_Constant(&currValue)))
return failure();
- APInt prevConstValue = prevValue.getValue();
- APInt currConstValue = currValue.getValue();
+ // Ensure that previous divisor is a multiple of the current divisor. If
+ // not, fail the transformation.
+ bool isApplicable = false;
+ if (auto prevInt = dyn_cast<IntegerAttr>(prevValue)) {
+ auto currInt = dyn_cast<IntegerAttr>(currValue);
+ isApplicable = prevInt.getValue().urem(currInt.getValue()) == 0;
+ } else if (auto prevVec = dyn_cast<DenseElementsAttr>(prevValue)) {
+ auto currVec = dyn_cast<DenseElementsAttr>(currValue);
----------------
IgWod-IMG wrote:
`cast` here as well. Just so you don't miss it :)
https://github.com/llvm/llvm-project/pull/141902
More information about the Mlir-commits
mailing list