Skip to content

Legalization failure for mgmt.modreduce in secret generic conversion #2487

@sairam2661

Description

@sairam2661

Test commit
a413796feb31eb6a1e70160308defe4d0250d09e

Description
The --secret-to-mod-arith pass triggers a fatal error during the conversion of a secret.generic operation containing a mgmt.modreduce op.

Steps to reproduce

  • Minimal MLIR program (test.mlir)
"builtin.module"() ({
  "func.func"() <{
    function_type = (!secret.secret<tensor<8xi8>>) -> !secret.secret<tensor<8xi8>>,
    sym_name = "main"
  }> ({
  ^bb0(%arg0: !secret.secret<tensor<8xi8>>):
    %0 = "secret.generic"(%arg0) ({
    ^bb0(%arg1: tensor<8xi8>):
      %1 = "mgmt.modreduce"(%arg1) : (tensor<8xi8>) -> tensor<8xi8>
      "secret.yield"(%1) : (tensor<8xi8>) -> ()
    }) : (!secret.secret<tensor<8xi8>>) -> !secret.secret<tensor<8xi8>>
    "func.return"(%0) : (!secret.secret<tensor<8xi8>>) -> ()
  }) : () -> ()
}) : () -> ()

Command

heir-opt --secret-to-mod-arith=modulus=17 test.mlir

Output

LLVM ERROR: pattern 'mlir::heir::ConvertAnyNestedGeneric' produced IR that could not be legalized. new ops: {mgmt.modreduce}, modified ops: {}, inserted block into ops: {}
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: /workdir/heir/bin/heir-opt --secret-to-mod-arith=modulus=17 test.mlir
 #0 0x000055bea4c629c6 ___interceptor_backtrace (/workdir/heir/bin/heir-opt+0x5b549c6)
 #1 0x000055beb041b1c2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /proc/self/cwd/external/llvm-project/llvm/lib/Support/Unix/Signals.inc:838:8
 #2 0x000055beb041c001 llvm::sys::RunSignalHandlers() /proc/self/cwd/external/llvm-project/llvm/lib/Support/Signals.cpp:105:18
 #3 0x000055beb041c001 SignalHandler(int, siginfo_t*, void*) /proc/self/cwd/external/llvm-project/llvm/lib/Support/Unix/Signals.inc:409:3
 #4 0x00007f6f31fd8520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #5 0x00007f6f3202c9fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #6 0x00007f6f31fd8476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #7 0x00007f6f31fbe7f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #8 0x000055beb036de78 llvm::report_fatal_error(llvm::Twine const&, bool) /proc/self/cwd/external/llvm-project/llvm/lib/Support/ErrorHandling.cpp:137:5
 #9 0x000055beaeead5b6 reportNewIrLegalizationFatalError(mlir::Pattern const&, llvm::SetVector<mlir::Operation*, llvm::SmallVector<mlir::Operation*, 0u>, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void> >, 0u> const&, llvm::SetVector<mlir::Operation*, llvm::SmallVector<mlir::Operation*, 0u>, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void> >, 0u> const&, llvm::SetVector<mlir::Block*, llvm::SmallVector<mlir::Block*, 0u>, llvm::DenseSet<mlir::Block*, llvm::DenseMapInfo<mlir::Block*, void> >, 0u> const&) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:0:3
#10 0x000055beaeead5b6 (anonymous namespace)::OperationLegalizer::legalizeWithPattern(mlir::Operation*)::$_2::operator()(mlir::Pattern const&) const /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2757:9
#11 0x000055beaeead5b6 llvm::LogicalResult llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>::callback_fn<(anonymous namespace)::OperationLegalizer::legalizeWithPattern(mlir::Operation*)::$_2>(long, mlir::Pattern const&) /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
#12 0x000055beaefbb61e 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&)>)::$_0::operator()() const /proc/self/cwd/external/llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:229:15
#13 0x000055beaefbb61e void llvm::function_ref<void ()>::callback_fn<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&)>)::$_0>(long) /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
#14 0x000055beaefb7375 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&)>) /proc/self/cwd/external/llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:197:5
#15 0x000055beaee90c5c (anonymous namespace)::OperationLegalizer::legalizeWithPattern(mlir::Operation*) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2767:21
#16 0x000055beaee90c5c (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2533:17
#17 0x000055beaee8f170 mlir::OperationConverter::convert(mlir::Operation*) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:3288:7
#18 0x000055beaee91a80 mlir::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:3385:0
#19 0x000055beaeeb25af applyConversion(llvm::ArrayRef<mlir::Operation*>, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig, (anonymous namespace)::OpConversionMode)::$_0::operator()() const /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:4107:9
#20 0x000055beaeeb25af void llvm::function_ref<void ()>::callback_fn<applyConversion(llvm::ArrayRef<mlir::Operation*>, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig, (anonymous namespace)::OpConversionMode)::$_0>(long) /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
#21 0x000055beaee9f633 applyConversion(llvm::ArrayRef<mlir::Operation*>, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig, (anonymous namespace)::OpConversionMode) /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:0:12
#22 0x000055beaee9f95a mlir::applyPartialConversion(llvm::ArrayRef<mlir::Operation*>, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:4120:10
#23 0x000055beaee9f95a mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:4127:10
#24 0x000055bea51d10d8 mlir::heir::SecretToModArith::runOnOperation() /proc/self/cwd/lib/Dialect/Secret/Conversions/SecretToModArith/SecretToModArith.cpp:421:16
#25 0x000055beaf742537 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_3::operator()() const /proc/self/cwd/external/llvm-project/mlir/lib/Pass/Pass.cpp:610:22
#26 0x000055beaf742537 void llvm::function_ref<void ()>::callback_fn<mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_3>(long) /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
#27 0x000055beaf730270 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /proc/self/cwd/external/llvm-project/mlir/lib/Pass/Pass.cpp:603:3
#28 0x000055beaf731d95 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /proc/self/cwd/external/llvm-project/mlir/lib/Pass/Pass.cpp:682:9
#29 0x000055beaf73fb06 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /proc/self/cwd/external/llvm-project/mlir/lib/Pass/Pass.cpp:1117:10
#30 0x000055beaf73e263 mlir::PassManager::run(mlir::Operation*) /proc/self/cwd/external/llvm-project/mlir/lib/Pass/Pass.cpp:0:60
#31 0x000055bea88204b1 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) /proc/self/cwd/external/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:568:7
#32 0x000055bea881e78e 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*) /proc/self/cwd/external/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:0:12
#33 0x000055bea881e78e mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_0::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::MemoryBufferRef, llvm::raw_ostream&) const /proc/self/cwd/external/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:733:12
#34 0x000055bea881e78e 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&)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::MemoryBufferRef const&, llvm::raw_ostream&) /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
#35 0x000055beafbe1a79 llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::MemoryBufferRef const&, llvm::raw_ostream&) const /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:0
#36 0x000055beafbe1a79 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)::$_0::operator()(llvm::StringRef) const /proc/self/cwd/external/llvm-project/mlir/lib/Support/ToolUtilities.cpp:94:13
#37 0x000055beafbe0cef void llvm::interleave<llvm::StringRef const*, 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)::$_0, void llvm::interleave<llvm::SmallVector<llvm::StringRef, 8u>, 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)::$_0, llvm::raw_ostream, llvm::StringRef>(llvm::SmallVector<llvm::StringRef, 8u> const&, llvm::raw_ostream&, 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)::$_0, llvm::StringRef const&)::'lambda'(), void>(llvm::SmallVector<llvm::StringRef, 8u>, llvm::SmallVector<llvm::StringRef, 8u>, 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)::$_0, llvm::raw_ostream) /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/STLExtras.h:2179:16
#38 0x000055beafbe0cef void llvm::interleave<llvm::SmallVector<llvm::StringRef, 8u>, 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)::$_0, llvm::raw_ostream, llvm::StringRef>(llvm::SmallVector<llvm::StringRef, 8u> const&, llvm::raw_ostream&, 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)::$_0, llvm::StringRef const&) /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/STLExtras.h:2199:3
#39 0x000055beafbe0cef 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) /proc/self/cwd/external/llvm-project/mlir/lib/Support/ToolUtilities.cpp:97:3
#40 0x000055bea8816fff mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) /proc/self/cwd/external/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:738:26
#41 0x000055bea8817b99 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) /proc/self/cwd/external/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:784:0
#42 0x000055bea88183ce mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) /proc/self/cwd/external/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:800:10
#43 0x000055bea4cfebe1 mlir::asMainReturnCode(llvm::LogicalResult) /proc/self/cwd/external/llvm-project/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h:0:0
#44 0x000055bea4cfebe1 main /proc/self/cwd/tools/heir-opt.cpp:463:10
#45 0x00007f6f31fbfd90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#46 0x00007f6f31fbfe40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#47 0x000055bea4c1c025 _start (/workdir/heir/bin/heir-opt+0x5b0e025)
Aborted

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions