| Issue |
237820
|
| Summary |
[mlir][bug][fuzzer-found] --test-vector-transferop-opt aborts on i32 scf.for bounds during ValueBounds inference
|
| Labels |
mlir
|
| Assignees |
|
| Reporter |
Kiritobl
|
#### Version
git commit hash: 982197fad060f461277020c0ca413d93a5f2a8a6
LLVM/MLIR 24.0.0git, optimized build with assertions.
#### Bug Description
`--test-vector-transferop-opt` aborts in `ValueBoundsConstraintSet::getExpr` while checking whether a `vector.transfer_write` and a later `vector.transfer_read` are disjoint. The read index is the `index` result of an `scf.for` whose lower bound, upper bound and step are `i32`; the SCF ValueBounds model passes those integer-typed bounds to `getExpr`, which rejects them because `ValueBoundsOptions::allowIntegerType` is `false`.
The minimized input below parses and verifies successfully without the pass. It was found by fuzzing and reduced by hand to one write, one `i32` `scf.for` carrying an `index` iter_arg, and one read. The process aborted in all 10 repeated runs on this build.
#### Crash Chain & Root Cause
Crash chain:
```text
--test-vector-transferop-opt
→ TestVectorTransferOpt::runOnOperation
→ vector::transferOpflowOpt
→ TransferOptimization::deadStoreOp
→ vector::isDisjointTransferSet
→ vector::isDisjointTransferIndices
→ affine::fullyComposeAndComputeConstantDelta
→ ValueBoundsConstraintSet::computeConstantBound
→ ValueBoundsConstraintSet::processWorklist
→ scf::ForOpInterface::populateBoundsForIndexValue
→ scf::ForOpInterface::populateIterArgBounds
→ ValueBoundsConstraintSet::getExpr
→ assertValidValueDim
→ llvm_unreachable("unsupported type")
```
`deadStoreOp` (`mlir/lib/Dialect/Vector/Transforms/VectorTransferOpTransforms.cpp:107`) scans users of the write's memref. When it reaches the read, it calls `isDisjointTransferSet(..., testDynamicValueUsingBounds=true)` (`:169-172`). `isDisjointTransferIndices` (`VectorOps.cpp:275-334`) sees a dynamic read index and calls `fullyComposeAndComputeConstantDelta` (`ValueBoundsOpInterfaceImpl.cpp:229-243`), which queries `computeConstantBound` for the loop result.
`scf::ForOpInterface::populateIterArgBounds` (`mlir/lib/Dialect/SCF/IR/ValueBoundsOpInterfaceImpl.cpp:72-123`) derives a closed form for the `index` result. To do so it calls `getExpr` on the loop's lower/upper bounds and step (`:107-122`, via `getTripCountExpr` at `:20-29`). Those values are `i32` in the reproducer. `ValueBoundsOptions::allowIntegerType` defaults to `false` (`ValueBoundsOpInterface.h:61-65`), so `assertValidValueDim` (`ValueBoundsOpInterface.cpp:206-220`) treats them as unsupported and reaches `llvm_unreachable("unsupported type")` at `:217`.
Changing the loop bounds/step to `index` makes the pass succeed; changing the read index to a constant also makes it succeed. On the original fuzzer input, keeping the i64 `unrealized_conversion_cast` and i32 iter_arg but changing only the loop bounds/step to `index` is likewise sufficient to avoid the crash. The unsupported values are therefore the integer-typed loop bounds, not the loop result itself.
The pass should handle this verifier-accepted input without aborting; if the integer loop bounds cannot be modeled, the bounds query can conservatively fail.
#### Steps to Reproduce
```bash
mlir-opt --test-vector-transferop-opt reproducer.mlir -o /dev/null
```
The process terminates with `SIGABRT` (shell exit status 134). It aborted in 10/10 runs on this build. Running `mlir-opt reproducer.mlir -o /dev/null` without the pass succeeds.
#### Reproducer (`reproducer.mlir`)
```mlir
func.func @f(%m: memref<1xf32>, %v: vector<1xf32>) {
%c0 = arith.constant 0 : index
%c0i = arith.constant 0 : i32
%c1i = arith.constant 1 : i32
%f0 = arith.constant 0.0 : f32
vector.transfer_write %v, %m[%c0] : vector<1xf32>, memref<1xf32>
%r = scf.for %i = %c0i to %c1i step %c1i iter_args(%it = %c0) -> (index) : i32 {
scf.yield %it : index
}
%x = vector.transfer_read %m[%r], %f0 : memref<1xf32>, vector<1xf32>
return
}
```
#### Stack Dump
The following block is the unmodified stderr from running the command above with this build:
```text
unsupported type
UNREACHABLE executed at /12T/qin/Fuzzing/MLIR_latest_20261028/llvm-project/mlir/lib/Interfaces/ValueBoundsOpInterface.cpp:217!
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-vector-transferop-opt reproducer.mlir -o /dev/null
#0 0x000055a23c0f7819 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x1fbb819)
#1 0x000055a23c0f401c llvm::sys::RunSignalHandlers() (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x1fb801c)
#2 0x000055a23c0f4186 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007f91583ea520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007f915843e9bc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007f915843e9bc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x00007f915843e9bc pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x00007f91583ea476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007f91583d07f3 abort ./stdlib/abort.c:81:7
#9 0x000055a23c0d7f9e (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x1f9bf9e)
#10 0x000055a24481c7c1 assertValidValueDim(mlir::Value, std::optional<long>, mlir::ValueBoundsOptions) (.isra.0) ValueBoundsOpInterface.cpp:0:0
#11 0x000055a24481dfe0 mlir::ValueBoundsConstraintSet::getExpr(mlir::Value, std::optional<long>) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa6e1fe0)
#12 0x000055a24411cbd1 mlir::scf::(anonymous namespace)::ForOpInterface::populateIterArgBounds(mlir::scf::ForOp, mlir::Value, std::optional<long>, mlir::ValueBoundsConstraintSet&) ValueBoundsOpInterfaceImpl.cpp:0:0
#13 0x000055a24411d1ac mlir::detail::ValueBoundsOpInterfaceInterfaceTraits::FallbackModel<mlir::scf::(anonymous namespace)::ForOpInterface>::populateBoundsForIndexValue(mlir::detail::ValueBoundsOpInterfaceInterfaceTraits::Concept const*, mlir::Operation*, mlir::Value, mlir::ValueBoundsConstraintSet&) ValueBoundsOpInterfaceImpl.cpp:0:0
#14 0x000055a244821621 mlir::ValueBoundsConstraintSet::processWorklist() (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa6e5621)
#15 0x000055a244821b6f mlir::ValueBoundsConstraintSet::computeConstantBound(mlir::presburger::BoundType, mlir::ValueBoundsConstraintSet::Variable const&, std::function<bool (mlir::Value, std::optional<long>, mlir::ValueBoundsConstraintSet&)> const&, mlir::ValueBoundsOptions) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa6e5b6f)
#16 0x000055a244252c5e mlir::affine::fullyComposeAndComputeConstantDelta(mlir::Value, mlir::Value) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa116c5e)
#17 0x000055a242e4ca00 mlir::vector::isDisjointTransferIndices(mlir::VectorTransferOpInterface, mlir::VectorTransferOpInterface, bool) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x8d10a00)
#18 0x000055a242e4cb5c mlir::vector::isDisjointTransferSet(mlir::VectorTransferOpInterface, mlir::VectorTransferOpInterface, bool) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x8d10b5c)
#19 0x000055a2427311e4 (anonymous namespace)::TransferOptimization::deadStoreOp(mlir::vector::TransferWriteOp) VectorTransferOpTransforms.cpp:0:0
#20 0x000055a242733379 void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (.constprop.0) VectorTransferOpTransforms.cpp:0:0
#21 0x000055a242733210 void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (.constprop.0) VectorTransferOpTransforms.cpp:0:0
#22 0x000055a242733610 mlir::vector::transferOpflowOpt(mlir::RewriterBase&, mlir::Operation*) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x85f7610)
#23 0x000055a23ca48d79 (anonymous namespace)::TestVectorTransferOpt::runOnOperation() TestVectorTransforms.cpp:0:0
#24 0x000055a2446c96d9 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa58d6d9)
#25 0x000055a2446c99b4 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)
#26 0x000055a2446c85c4 mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa58c5c4)
#27 0x000055a2446c95b1 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa58d5b1)
#28 0x000055a2446c99b4 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)
#29 0x000055a2446cb602 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa58f602)
#30 0x000055a2446cc5d9 mlir::PassManager::run(mlir::Operation*) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa5905d9)
#31 0x000055a23c1bfc69 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#32 0x000055a23c1c114e 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
#33 0x000055a23c1c1391 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
#34 0x000055a244a415ed 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)
#35 0x000055a23c1bb15a 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
#36 0x000055a23c1c19d1 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x20859d1)
#37 0x000055a23c1c1c24 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x2085c24)
#38 0x000055a23c0928c7 main (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x1f568c7)
#39 0x00007f91583d1d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#40 0x00007f91583d1e40 call_init ./csu/../csu/libc-start.c:128:20
#41 0x00007f91583d1e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#42 0x000055a23c0d70b5 _start (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x1f9b0b5)
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs