[Mlir-commits] [mlir] [mlir][ArithToLLVM] Fix index lowering for addui_extended (PR #223265)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Sep 13 11:31:29 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Bruce Xi (brucexi999)
<details>
<summary>Changes</summary>
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. Add a
regression test covering both 32-bit and 64-bit index lowering.
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 regression test fails without the fix and passes with it. All six
ArithToLLVM test files pass with assertions enabled on upstream base
`4098f568c4`.
Addresses the lowering failure reported in
https://github.com/llvm/llvm-project/issues/84986.
Assisted-by: Codex
---
Full diff: https://github.com/llvm/llvm-project/pull/223265.diff
2 Files Affected:
- (modified) mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp (+2-1)
- (added) mlir/test/Conversion/ArithToLLVM/arith-to-llvm-index.mlir (+14)
``````````diff
diff --git a/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp b/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
index 982b1e5e9a8d1..5cfa0a712ef53 100644
--- a/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
+++ b/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
@@ -559,9 +559,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/arith-to-llvm-index.mlir b/mlir/test/Conversion/ArithToLLVM/arith-to-llvm-index.mlir
new file mode 100644
index 0000000000000..a5b24753979b9
--- /dev/null
+++ b/mlir/test/Conversion/ArithToLLVM/arith-to-llvm-index.mlir
@@ -0,0 +1,14 @@
+// RUN: mlir-opt %s -convert-arith-to-llvm="index-bitwidth=32" | FileCheck %s --check-prefix=INDEX32
+// RUN: mlir-opt %s -convert-arith-to-llvm="index-bitwidth=64" | FileCheck %s --check-prefix=INDEX64
+
+// The sum's type must be converted to the configured index width when building
+// the LLVM struct that holds the sum and overflow indicator.
+
+// INDEX32-LABEL: func.func @addui_extended_index(
+// INDEX32: "llvm.intr.uadd.with.overflow"{{.*}} : (i32, i32) -> !llvm.struct<(i32, i1)>
+// INDEX64-LABEL: func.func @addui_extended_index(
+// INDEX64: "llvm.intr.uadd.with.overflow"{{.*}} : (i64, i64) -> !llvm.struct<(i64, 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
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/223265
More information about the Mlir-commits
mailing list