diff --git a/mlir/lib/IR/AffineExpr.cpp b/mlir/lib/IR/AffineExpr.cpp --- a/mlir/lib/IR/AffineExpr.cpp +++ b/mlir/lib/IR/AffineExpr.cpp @@ -833,7 +833,8 @@ // Note, this may not be valid if we ever allow negative modulus constants if (lBin && lBin.getKind() == AffineExprKind::Mod) { auto intermediate = lBin.getRHS().dyn_cast(); - if (mod(intermediate.getValue(), rhsConst.getValue()) == 0) { + if (intermediate && + mod(intermediate.getValue(), rhsConst.getValue()) == 0) { return lBin.getLHS() % rhsConst.getValue(); } }