Skip to content

Inconsistent results and crash when using --int-range-optimizations #81228

@AnonymousBugreporter1

Description

@AnonymousBugreporter1

I have the MLIR program:

test.mlir.txt

When I run the following command on the above MLIR program, I will get inconsistent results over multiple runs:
command:

mlir-opt --int-range-optimizations --canonicalize --convert-arith-to-llvm test.mlir

possible result 1:

module {
  func.func @func1() {
    %0 = llvm.mlir.constant(3743431372 : i64) : i64
    %1 = llvm.mlir.constant(true) : i1
    vector.print %1 : i1
    vector.print %0 : i64
    return
  }
}

possible result 2:

module {
  func.func @func1() {
    %0 = llvm.mlir.constant(3743431372 : i64) : i64
    %1 = llvm.mlir.constant(false) : i1
    vector.print %1 : i1
    vector.print %0 : i64
    return
  }
}

I've tried to reduce the program, but after reducing it, the error then changed into crash.
The reduced program:
test.mlir:

module {
  func.func @func1() {
    %false = arith.constant false
    %false_0 = arith.constant false
    // These two constant values can just be declared as both true or both false and cannot be removed

    %c2_i16 = arith.constant 2 : i16
    %7 = arith.addi %c2_i16, %c2_i16 : i16
    %31 = math.absi %c2_i16 : i16
    // This operation can be changed to math.cttz or math.ctlz, but then the frequency of causing crashes will change from always to sometimes

    %32 = arith.cmpi sge, %7, %31 : i16
    //This comparison attribute can be any type supported in the arith.cmpi operation

    vector.print %32 : i1
    return
  }
}

The above MLIR program will cause a crash when using the following command:

mlir-opt --int-range-optimizations test.mlir

And the crash backtrace is:

mlir-opt: /data/tmp/v0209/llvm-project/llvm/lib/Support/APInt.cpp:291: int llvm::APInt::compareSigned(const llvm::APInt&) const: Assertion `BitWidth == RHS.BitWidth && "Bit widths must be same for comparison"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /data/tmp/v0209/llvm-project/build/bin/mlir-opt --int-range-optimizations test.mlir
 #0 0x000055bb113871df llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/tmp/v0209/llvm-project/build/bin/mlir-opt+0x17141df)
 #1 0x000055bb11384234 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f8b1d00e420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f8b1cadb00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007f8b1caba859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x00007f8b1caba729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #6 0x00007f8b1cacbfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #7 0x000055bb11412f2d llvm::APInt::compareSigned(llvm::APInt const&) const (/data/tmp/v0209/llvm-project/build/bin/mlir-opt+0x179ff2d)
 #8 0x000055bb116d428f handleSge(mlir::ConstantIntRanges, mlir::ConstantIntRanges) IntRangeOptimizations.cpp:0:0
 #9 0x000055bb116d547c (anonymous namespace)::ConvertCmpOp::matchAndRewrite(mlir::arith::CmpIOp, mlir::PatternRewriter&) const IntRangeOptimizations.cpp:0:0
#10 0x000055bb17049288 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>) (/data/tmp/v0209/llvm-project/build/bin/mlir-opt+0x73d6288)
#11 0x000055bb142bb0ef (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#12 0x000055bb142bdf8b mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/data/tmp/v0209/llvm-project/build/bin/mlir-opt+0x464af8b)
#13 0x000055bb116d6bfe (anonymous namespace)::IntRangeOptimizationsPass::runOnOperation() IntRangeOptimizations.cpp:0:0
#14 0x000055bb142075ae mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/tmp/v0209/llvm-project/build/bin/mlir-opt+0x45945ae)
#15 0x000055bb14207a8a mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/tmp/v0209/llvm-project/build/bin/mlir-opt+0x4594a8a)
#16 0x000055bb14208244 mlir::PassManager::run(mlir::Operation*) (/data/tmp/v0209/llvm-project/build/bin/mlir-opt+0x4595244)
#17 0x000055bb141f9003 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#18 0x000055bb141fa584 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPool*) MlirOptMain.cpp:0:0
#19 0x000055bb141fa734 mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, 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::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#20 0x000055bb142f70e4 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, bool, bool) (/data/tmp/v0209/llvm-project/build/bin/mlir-opt+0x46840e4)
#21 0x000055bb141f2b97 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/tmp/v0209/llvm-project/build/bin/mlir-opt+0x457fb97)
#22 0x000055bb141fa881 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/tmp/v0209/llvm-project/build/bin/mlir-opt+0x4587881)
#23 0x000055bb141fad06 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/tmp/v0209/llvm-project/build/bin/mlir-opt+0x4587d06)
#24 0x000055bb112bc58b main (/data/tmp/v0209/llvm-project/build/bin/mlir-opt+0x164958b)
#25 0x00007f8b1cabc083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#26 0x000055bb11356dee _start (/data/tmp/v0209/llvm-project/build/bin/mlir-opt+0x16e3dee)
Aborted (core dumped)

I'm not sure if there is any problem in the arith compare operations, or maybe in the --int-range-optimizations pass that caused the above errors.
My git version is f608269.

Metadata

Metadata

Assignees

Labels

crashPrefer [crash-on-valid] or [crash-on-invalid]mlir

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions