Skip to content

Replacement value count mismatch in secret generic conversion #2482

@sairam2661

Description

@sairam2661

Test commit
a413796feb31eb6a1e70160308defe4d0250d09e

Description
The --secret-to-mod-arith pass crashes when a secret.generic operation yields multiple results.

Steps to reproduce

  • Minimal MLIR program (test.mlir)
"builtin.module"() ({
  "func.func"() <{
    function_type = (!secret.secret<i16>) -> (!secret.secret<i16>, !secret.secret<i16>),
    sym_name = "multi_output"
  }> ({
  ^bb0(%arg0: !secret.secret<i16>):
    %0 = "arith.constant"() <{value = 2 : i16}> : () -> i16
    %1:2 = "secret.generic"(%arg0) ({
    ^bb0(%arg1: i16):
      %2 = "arith.muli"(%arg1, %0) : (i16, i16) -> i16
      "secret.yield"(%2, %2) : (i16, i16) -> ()
    }) : (!secret.secret<i16>) -> (!secret.secret<i16>, !secret.secret<i16>)
    "func.return"(%1#0, %1#1) : (!secret.secret<i16>, !secret.secret<i16>) -> ()
  }) : () -> ()
}) : () -> ()

Command

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

Output

heir-opt: external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2074: virtual void mlir::ConversionPatternRewriter::replaceOp(Operation *, ValueRange): Assertion `op->getNumResults() == newValues.size() && "incorrect # of replacement values"' 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: /workdir/heir/bin/heir-opt --secret-to-mod-arith=modulus=17 test.mlir
 #0 0x00005612c75b29c6 ___interceptor_backtrace (/workdir/heir/bin/heir-opt+0x5b549c6)
 #1 0x00005612d2d6b1c2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /proc/self/cwd/external/llvm-project/llvm/lib/Support/Unix/Signals.inc:838:8
 #2 0x00005612d2d6c001 llvm::sys::RunSignalHandlers() /proc/self/cwd/external/llvm-project/llvm/lib/Support/Signals.cpp:105:18
 #3 0x00005612d2d6c001 SignalHandler(int, siginfo_t*, void*) /proc/self/cwd/external/llvm-project/llvm/lib/Support/Unix/Signals.inc:409:3
 #4 0x00007fc4841b7520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #5 0x00007fc48420b9fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #6 0x00007fc4841b7476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #7 0x00007fc48419d7f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #8 0x00007fc48419d71b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #9 0x00007fc4841aee96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#10 0x00005612d17d5a53 mlir::ConversionPatternRewriter::replaceOp(mlir::Operation*, mlir::ValueRange) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2075:3
#11 0x00005612d17d4ed5 mlir::ConversionPatternRewriter::replaceOp(mlir::Operation*, mlir::Operation*) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2070:1
#12 0x00005612c7b27700 mlir::heir::SecretGenericOpCipherPlainConversion<mlir::arith::MulIOp, mlir::heir::mod_arith::MulOp>::matchAndRewriteInner(mlir::heir::secret::GenericOp, mlir::TypeRange, mlir::ValueRange, mlir::ConversionPatternRewriter&) const /proc/self/cwd/lib/Dialect/Secret/Conversions/SecretToModArith/SecretToModArith.cpp:348:3
#13 0x00005612c7b2708c mlir::heir::SecretGenericOpConversion<mlir::arith::MulIOp, mlir::heir::mod_arith::MulOp>::matchAndRewrite(mlir::heir::secret::GenericOp, mlir::heir::secret::GenericOpAdaptor, mlir::ConversionPatternRewriter&) const /proc/self/cwd/lib/Dialect/Secret/Conversions/SecretToModArith/SecretToModArith.cpp:130:9
#14 0x00005612c77356c1 llvm::LogicalResult mlir::ConversionPattern::dispatchTo1To1<mlir::OpConversionPattern<mlir::heir::secret::GenericOp>, mlir::heir::secret::GenericOp>(mlir::OpConversionPattern<mlir::heir::secret::GenericOp> const&, mlir::heir::secret::GenericOp, mlir::heir::secret::GenericOp::GenericAdaptor<llvm::ArrayRef<mlir::ValueRange> >, mlir::ConversionPatternRewriter&) /proc/self/cwd/external/llvm-project/mlir/include/mlir/Transforms/DialectConversion.h:1025:15
#15 0x00005612c77353b3 mlir::OpConversionPattern<mlir::heir::secret::GenericOp>::matchAndRewrite(mlir::heir::secret::GenericOp, mlir::heir::secret::GenericOpGenericAdaptor<llvm::ArrayRef<mlir::ValueRange> >, mlir::ConversionPatternRewriter&) const /proc/self/cwd/external/llvm-project/mlir/include/mlir/Transforms/DialectConversion.h:727:12
#16 0x00005612c7735005 mlir::OpConversionPattern<mlir::heir::secret::GenericOp>::matchAndRewrite(mlir::Operation*, llvm::ArrayRef<mlir::ValueRange>, mlir::ConversionPatternRewriter&) const /proc/self/cwd/external/llvm-project/mlir/include/mlir/Transforms/DialectConversion.h:713:12
#17 0x00005612d17dc771 mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:0:10
#18 0x00005612d190b112 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:0:31
#19 0x00005612d190b112 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
#20 0x00005612d1907375 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
#21 0x00005612d17e0c5c (anonymous namespace)::OperationLegalizer::legalizeWithPattern(mlir::Operation*) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2767:21
#22 0x00005612d17e0c5c (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2533:17
#23 0x00005612d17df170 mlir::OperationConverter::convert(mlir::Operation*) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:3288:7
#24 0x00005612d17e1a80 mlir::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:3385:0
#25 0x00005612d18025af 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
#26 0x00005612d18025af 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
#27 0x00005612d17ef633 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
#28 0x00005612d17ef95a 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
#29 0x00005612d17ef95a 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
#30 0x00005612c7b210d8 mlir::heir::SecretToModArith::runOnOperation() /proc/self/cwd/lib/Dialect/Secret/Conversions/SecretToModArith/SecretToModArith.cpp:421:16
...
#47 0x00005612cb167b99 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
#48 0x00005612cb1683ce mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) /proc/self/cwd/external/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:800:10
#49 0x00005612c764ebe1 mlir::asMainReturnCode(llvm::LogicalResult) /proc/self/cwd/external/llvm-project/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h:0:0
#50 0x00005612c764ebe1 main /proc/self/cwd/tools/heir-opt.cpp:463:10
#51 0x00007fc48419ed90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#52 0x00007fc48419ee40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#53 0x00005612c756c025 _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