Issue 237494
Summary [MLIR][Math][fuzzer-found] math.fpowi strength reduction aborts on wide constant exponents
Labels mlir
Assignees
Reporter Kiritobl
    #### Version

git commit hash: 982197fad060f461277020c0ca413d93a5f2a8a6

LLVM/MLIR 24.0.0git, optimized build with assertions.

#### Bug Description

`--test-math-algebraic-simplification` aborts on two verifier-accepted `math.fpowi` operations whose constant exponents have types `i104` and `i112`. Both inputs consist of one `math.fpowi` and its required exponent constant. Each input parses and verifies successfully without the pass.

The exponent values, `18446744073709551578` and `18446744073709551558`, are positive in their respective integer types but exceed the signed `int64_t` range. Both commands below terminate with SIGABRT.

#### Crash Chain & Root Cause

Crash chain:

```text
`--test-math-algebraic-simplification`
  → `PowIStrengthReduction<math::FPowIOp>::matchAndRewrite()`
  → `IntegerAttr::getInt()`
  → `APInt::getSExtValue()`
  → `getSignificantBits() <= 64` assertion
```

`PowIStrengthReduction` calls `getInt()` on a constant exponent before checking whether its magnitude exceeds the strength-reduction threshold. `IntegerAttr::getInt()` calls `APInt::getSExtValue()`, which asserts when the signed value cannot fit in `int64_t`. The `math.fpowi` operation accepts signless integer exponent types wider than 64 bits, so the transformation must check whether the exponent fits before converting it, or decline the rewrite without aborting.

#### Steps to Reproduce

Run each command with the corresponding reproducer below:

```bash
mlir-opt --test-math-algebraic-simplification reproducer-i104.mlir -o /dev/null
mlir-opt --test-math-algebraic-simplification reproducer-i112.mlir -o /dev/null
```

Each process terminates with `SIGABRT` (shell exit status 134). Running `mlir-opt <reproducer>.mlir -o /dev/null` without the pass succeeds for both inputs.

#### Reproducer (`reproducer-*.mlir`)

`reproducer-i104.mlir`:

```mlir
module {
  func.func @f(%base: f32) -> f32 {
    %exponent = arith.constant 18446744073709551578 : i104
    %result = math.fpowi %base, %exponent : f32, i104
    return %result : f32
  }
}
```

`reproducer-i112.mlir`:

```mlir
module {
  func.func @f(%base: f32) -> f32 {
    %exponent = arith.constant 18446744073709551558 : i112
    %result = math.fpowi %base, %exponent : f32, i112
    return %result : f32
  }
}
```

#### Stack Dump

The following blocks are the unmodified stderr from running each command above with this build:

`reproducer-i104.mlir`:

```text
mlir-opt: /12T/qin/Fuzzing/MLIR_latest_20261028/llvm-project/llvm/include/llvm/ADT/APInt.h:1585: int64_t llvm::APInt::getSExtValue() const: Assertion `getSignificantBits() <= 64 && "Too many bits for int64_t"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.	Program arguments: /12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt --test-math-algebraic-simplification reproducer-i104.mlir -o /dev/null
 #0 0x0000559168abe819 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x1fbb819)
 #1 0x0000559168abb01c llvm::sys::RunSignalHandlers() (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x1fb801c)
 #2 0x0000559168abb186 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007f80b64ef520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f80b65439bc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007f80b65439bc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007f80b65439bc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007f80b64ef476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007f80b64d57f3 abort ./stdlib/abort.c:81:7
 #9 0x00007f80b64d571b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007f80b64e6e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x00005591712f2c23 (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa7efc23)
#12 0x000055916c2f9392 (anonymous namespace)::PowIStrengthReduction<mlir::math::FPowIOp, mlir::arith::DivFOp, mlir::arith::MulFOp>::matchAndRewrite(mlir::math::FPowIOp, mlir::PatternRewriter&) const AlgebraicSimplification.cpp:0:0
#13 0x00005591710286ac mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>)::'lambda'()::operator()() const PatternApplicator.cpp:0:0
#14 0x0000559171029d8a mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa526d8a)
#15 0x0000559170fefdb3 (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#16 0x0000559170ff25f7 mlir::applyPatternsGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa4ef5f7)
#17 0x0000559168bf0b72 (anonymous namespace)::TestMathAlgebraicSimplificationPass::runOnOperation() TestAlgebraicSimplification.cpp:0:0
#18 0x00005591710906d9 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa58d6d9)
#19 0x00005591710909b4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa58d9b4)
#20 0x0000559171092602 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa58f602)
#21 0x00005591710935d9 mlir::PassManager::run(mlir::Operation*) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa5905d9)
#22 0x0000559168b86c69 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#23 0x0000559168b8814e processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, mlir::SourceMgrDiagnosticVerifierHandler*, llvm::ThreadPoolInterface*) MlirOptMain.cpp:0:0
#24 0x0000559168b88391 llvm::LogicalResult llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::'lambda'(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#25 0x00005591714085ed mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa9055ed)
#26 0x0000559168b8215a mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (.part.0) MlirOptMain.cpp:0:0
#27 0x0000559168b889d1 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x20859d1)
#28 0x0000559168b88c24 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x2085c24)
#29 0x0000559168a598c7 main (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x1f568c7)
#30 0x00007f80b64d6d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#31 0x00007f80b64d6e40 call_init ./csu/../csu/libc-start.c:128:20
#32 0x00007f80b64d6e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#33 0x0000559168a9e0b5 _start (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x1f9b0b5)
```

`reproducer-i112.mlir`:

```text
mlir-opt: /12T/qin/Fuzzing/MLIR_latest_20261028/llvm-project/llvm/include/llvm/ADT/APInt.h:1585: int64_t llvm::APInt::getSExtValue() const: Assertion `getSignificantBits() <= 64 && "Too many bits for int64_t"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.	Program arguments: /12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt --test-math-algebraic-simplification reproducer-i112.mlir -o /dev/null
 #0 0x000055911db29819 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x1fbb819)
 #1 0x000055911db2601c llvm::sys::RunSignalHandlers() (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x1fb801c)
 #2 0x000055911db26186 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007f55c44d1520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f55c45259bc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007f55c45259bc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007f55c45259bc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007f55c44d1476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007f55c44b77f3 abort ./stdlib/abort.c:81:7
 #9 0x00007f55c44b771b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007f55c44c8e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x000055912635dc23 (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa7efc23)
#12 0x0000559121364392 (anonymous namespace)::PowIStrengthReduction<mlir::math::FPowIOp, mlir::arith::DivFOp, mlir::arith::MulFOp>::matchAndRewrite(mlir::math::FPowIOp, mlir::PatternRewriter&) const AlgebraicSimplification.cpp:0:0
#13 0x00005591260936ac mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>)::'lambda'()::operator()() const PatternApplicator.cpp:0:0
#14 0x0000559126094d8a mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa526d8a)
#15 0x000055912605adb3 (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#16 0x000055912605d5f7 mlir::applyPatternsGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa4ef5f7)
#17 0x000055911dc5bb72 (anonymous namespace)::TestMathAlgebraicSimplificationPass::runOnOperation() TestAlgebraicSimplification.cpp:0:0
#18 0x00005591260fb6d9 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa58d6d9)
#19 0x00005591260fb9b4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa58d9b4)
#20 0x00005591260fd602 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa58f602)
#21 0x00005591260fe5d9 mlir::PassManager::run(mlir::Operation*) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa5905d9)
#22 0x000055911dbf1c69 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#23 0x000055911dbf314e processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, mlir::SourceMgrDiagnosticVerifierHandler*, llvm::ThreadPoolInterface*) MlirOptMain.cpp:0:0
#24 0x000055911dbf3391 llvm::LogicalResult llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::'lambda'(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#25 0x00005591264735ed mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa9055ed)
#26 0x000055911dbed15a mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (.part.0) MlirOptMain.cpp:0:0
#27 0x000055911dbf39d1 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x20859d1)
#28 0x000055911dbf3c24 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x2085c24)
#29 0x000055911dac48c7 main (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x1f568c7)
#30 0x00007f55c44b8d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#31 0x00007f55c44b8e40 call_init ./csu/../csu/libc-start.c:128:20
#32 0x00007f55c44b8e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#33 0x000055911db090b5 _start (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x<truncated>Please see the issue for the entire body.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to