[Mlir-commits] [mlir] [mlir] only fold llvm.mlir.constant when types match (PR #70318)

Mehdi Amini llvmlistbot at llvm.org
Thu Oct 26 12:59:19 PDT 2023


================
@@ -2757,7 +2757,18 @@ ConstantOp LLVM::ConstantOp::materialize(OpBuilder &builder, Attribute value,
 }
 
 // Constant op constant-folds to its value.
-OpFoldResult LLVM::ConstantOp::fold(FoldAdaptor) { return getValue(); }
+OpFoldResult LLVM::ConstantOp::fold(FoldAdaptor) {
+  if (auto integerValue = getValue().dyn_cast<IntegerAttr>();
+      integerValue && integerValue.getType() == getType()) {
+    return getValue();
+  }
+  if (auto floatValue = getValue().dyn_cast<FloatAttr>();
+      floatValue && floatValue.getType() == getType()) {
+    return getValue();
+  }
+
+  return {};
----------------
joker-eph wrote:

Why wouldn't the infra reject a fold when there is a type mismatch instead?

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


More information about the Mlir-commits mailing list