[Mlir-commits] [mlir] [mlir][math] Fix APInt assertion in IPowI folding for i1 types (PR #177874)
Miloš Poletanović
llvmlistbot at llvm.org
Sun Jan 25 11:49:34 PST 2026
https://github.com/milos1397 created https://github.com/llvm/llvm-project/pull/177874
Fixes #177831
I have added a guard clause at the beginning of the fold method lambda to skip folding if the bitwidth of the operands is less than 2. This prevents the folder from attempting to create an invalid `oneValue` for i1 types.
>From 7bc620e9567301b0070b4f5cba30c94e6f253017 Mon Sep 17 00:00:00 2001
From: Milos Poletanovic <mpoletanovic at syrmia.com>
Date: Sun, 25 Jan 2026 20:28:16 +0100
Subject: [PATCH] [mlir][math] Fix APInt assertion in IPowI folding for i1
types
---
mlir/lib/Dialect/Math/IR/MathOps.cpp | 2 ++
.../remove-dead-values-one-bit-width.mlir | 13 +++++++++++++
2 files changed, 15 insertions(+)
create mode 100644 mlir/test/Transforms/remove-dead-values-one-bit-width.mlir
diff --git a/mlir/lib/Dialect/Math/IR/MathOps.cpp b/mlir/lib/Dialect/Math/IR/MathOps.cpp
index bbeef0f6ee9e5..2e99160a22d4c 100644
--- a/mlir/lib/Dialect/Math/IR/MathOps.cpp
+++ b/mlir/lib/Dialect/Math/IR/MathOps.cpp
@@ -369,6 +369,8 @@ OpFoldResult math::IPowIOp::fold(FoldAdaptor adaptor) {
adaptor.getOperands(),
[](const APInt &base, const APInt &power) -> std::optional<APInt> {
unsigned width = base.getBitWidth();
+ if (width < 2)
+ return {};
auto zeroValue = APInt::getZero(width);
APInt oneValue{width, 1ULL, /*isSigned=*/true};
APInt minusOneValue{width, -1ULL, /*isSigned=*/true};
diff --git a/mlir/test/Transforms/remove-dead-values-one-bit-width.mlir b/mlir/test/Transforms/remove-dead-values-one-bit-width.mlir
new file mode 100644
index 0000000000000..d9140e94f0bdd
--- /dev/null
+++ b/mlir/test/Transforms/remove-dead-values-one-bit-width.mlir
@@ -0,0 +1,13 @@
+// RUN: mlir-opt --remove-dead-values %s -o - | FileCheck %s
+// NOTE: Assertions have been autogenerated by utils/generate-test-checks.py
+
+// CHECK-LABEL: func.func @main() {
+// CHECK: return
+// CHECK: }
+func.func @main() {
+ %1 = vector.constant_mask [0, 0] : vector<2x4xi1>
+ %2 = arith.constant dense<false> : vector<2x4xi1>
+ %5 = math.ipowi %1, %2 : vector<2x4xi1>
+ return
+}
+
More information about the Mlir-commits
mailing list