[Mlir-commits] [mlir] a5d2f05 - [mlir][ArithToLLVM] Fix index lowering for addui_extended (#223265)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Oct 9 08:01:41 PDT 2026
Author: Bruce Xi
Date: 2026-10-09T17:01:34+02:00
New Revision: a5d2f05b4ee64bd409a9b7aae3e1a2509c2a46ce
URL: https://github.com/llvm/llvm-project/commit/a5d2f05b4ee64bd409a9b7aae3e1a2509c2a46ce
DIFF: https://github.com/llvm/llvm-project/commit/a5d2f05b4ee64bd409a9b7aae3e1a2509c2a46ce.diff
LOG: [mlir][ArithToLLVM] Fix index lowering for addui_extended (#223265)
Lowering `arith.addui_extended` with `index` operands fails because the
LLVM
result struct uses the unconverted sum type, even though the operands
have
already been converted.
Convert the sum type before constructing the LLVM result struct. Extend
the
existing index-bitwidth tests to cover `arith.addui_extended` at 32-,
64-, and
128-bit widths, reusing their RUN lines. Rename
`constant-index-bitwidth.mlir`
to `index-bitwidth.mlir` to reflect the broader coverage.
This preserves the operation's existing `index` support and uses the
converted
index width for the overflow intrinsic. Related discussion of `index`
support
in extended arithmetic: https://github.com/llvm/llvm-project/pull/85973.
The index reproducer fails without the fix. All five ArithToLLVM test
files
pass with assertions enabled on upstream base `4098f568c4`, including
the
32-, 64-, and 128-bit index lowering checks.
Addresses the lowering failure reported in
https://github.com/llvm/llvm-project/issues/84986.
Assisted-by: Codex
Added:
mlir/test/Conversion/ArithToLLVM/index-bitwidth.mlir
Modified:
mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
Removed:
mlir/test/Conversion/ArithToLLVM/constant-index-bitwidth.mlir
################################################################################
diff --git a/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp b/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
index adbff5a3b472cf..bac19144d6ea7c 100644
--- a/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
+++ b/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
@@ -568,9 +568,10 @@ LogicalResult AddUIExtendedOpLowering::matchAndRewrite(
// Handle the scalar and 1D vector cases.
if (!isa<LLVM::LLVMArrayType>(operandType)) {
+ Type newSumType = typeConverter->convertType(sumResultType);
Type newOverflowType = typeConverter->convertType(overflowResultType);
Type structType =
- LLVM::LLVMStructType::getLiteral(ctx, {sumResultType, newOverflowType});
+ LLVM::LLVMStructType::getLiteral(ctx, {newSumType, newOverflowType});
Value addOverflow = LLVM::UAddWithOverflowOp::create(
rewriter, loc, structType, adaptor.getLhs(), adaptor.getRhs());
Value sumExtracted =
diff --git a/mlir/test/Conversion/ArithToLLVM/constant-index-bitwidth.mlir b/mlir/test/Conversion/ArithToLLVM/index-bitwidth.mlir
similarity index 81%
rename from mlir/test/Conversion/ArithToLLVM/constant-index-bitwidth.mlir
rename to mlir/test/Conversion/ArithToLLVM/index-bitwidth.mlir
index 4363286162bcc5..6989eff5235bd4 100644
--- a/mlir/test/Conversion/ArithToLLVM/constant-index-bitwidth.mlir
+++ b/mlir/test/Conversion/ArithToLLVM/index-bitwidth.mlir
@@ -58,6 +58,20 @@ func.func @resource_index_constant() -> vector<2xindex> {
return %0 : vector<2xindex>
}
+// The sum's type must be converted to the configured index width when building
+// the LLVM struct that holds the sum and overflow indicator.
+
+// CHECK32-LABEL: @addui_extended_index
+// CHECK32: "llvm.intr.uadd.with.overflow"{{.*}} : (i32, i32) -> !llvm.struct<(i32, i1)>
+// CHECK64-LABEL: @addui_extended_index
+// CHECK64: "llvm.intr.uadd.with.overflow"{{.*}} : (i64, i64) -> !llvm.struct<(i64, i1)>
+// CHECK128-LABEL: @addui_extended_index
+// CHECK128: "llvm.intr.uadd.with.overflow"{{.*}} : (i128, i128) -> !llvm.struct<(i128, i1)>
+func.func @addui_extended_index(%a: index, %b: index) -> (index, i1) {
+ %sum, %overflow = arith.addui_extended %a, %b : index, i1
+ return %sum, %overflow : index, i1
+}
+
{-#
dialect_resources: {
builtin: {
More information about the Mlir-commits
mailing list