[Mlir-commits] [mlir] [mlir][LLVMIR] Skip or and shl folding for mismatched constant types (PR #226026)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Sep 24 02:26:38 PDT 2026


AkunCube wrote:

> > In general, if feels more like a bug of the constant operation rather than a folder bug if the attribute type doesn't match the op type?
> 
> I agree. I don't think we should guard every folder everywhere: that's a lot of redundant checks where we likely should address the root cause instead.
> 
> I would consider this a problem with the constants, and it doesn't seem reasonable to me to make every folder defend against this.

Thanks for the feedback. The reproducer uses test.constant, which currently allows an integer attribute type to differ from its SSA result type. This is also used intentionally by the negative tests in mlir/test/Dialect/Arith/canonicalize.mlir, including nested_ori, added in #195588. That PR guards its Arith canonicalization patterns with IntAttrTypeMatchesResult rather than changing test.constant.

ConstantLike requires test.constant to fold successfully, so returning {} from its folder is not an option. Normal arith.constant and llvm.mlir.constant already reject the mismatch. The guards here apply the same type check at the LLVM folding site; I added it to both OrOp and ShlOp for consistency. Would you prefer changing test.constant and its dependent tests instead?



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


More information about the Mlir-commits mailing list