llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.03k stars 11.58k forks source link

Assertion in Sparse conditional constant propagation #47335

Closed 0c53a501-ffa9-431e-a710-087fff249999 closed 3 years ago

0c53a501-ffa9-431e-a710-087fff249999 commented 3 years ago
Bugzilla Link 47991
Resolution FIXED
Resolved on Nov 03, 2020 05:03
Version trunk
OS Linux
Attachments Simplified test case
CC @efriedma-quic,@fhahn
Fixed by commit(s) d68bed0fa94e

Extended Description

Hi,

I'm getting an assertion with the simple test case that was attached. It can be replicated with the following command:

opt -ipsccp -S simple.ll

The issue is dying in the following line:

%tmp4 = trunc i512 %tmp3 to i32

The truncate function in ConstantRange identifies that it is trying to convert from 8-bits to 32-bits, which triggers the assertion.

This is the callback trace:

opt: /llvm/llvm/lib/IR/ConstantRange.cpp:721: llvm::ConstantRange llvm::ConstantRange::truncate(uint32_t) const: Assertion `getBitWidth() > DstTySize && "Not a value truncation"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:

  1. Program arguments: opt -ipsccp -S simple.ll
  2. Running pass 'Interprocedural Sparse Conditional Constant Propagation' on module 'simple.ll'.

    ​0 0x00000000036eafe1 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /llvm/llvm/lib/Support/Unix/Signals.inc:563:0

    ​1 0x00000000036eb098 PrintStackTraceSignalHandler(void*) /llvm/llvm/lib/Support/Unix/Signals.inc:630:0

    ​2 0x00000000036e90a1 llvm::sys::RunSignalHandlers() /llvm/llvm/lib/Support/Signals.cpp:71:0

    ​3 0x00000000036eaa24 SignalHandler(int) /llvm/llvm/lib/Support/Unix/Signals.inc:405:0

    ​4 0x00007fe76acd15e0 __restore_rt (/lib64/libpthread.so.0+0xf5e0)

    ​5 0x00007fe7698531f7 raise (/lib64/libc.so.6+0x351f7)

    ​6 0x00007fe7698548e8 abort (/lib64/libc.so.6+0x368e8)

    ​7 0x00007fe76984c266 __assert_fail_base (/lib64/libc.so.6+0x2e266)

    ​8 0x00007fe76984c312 (/lib64/libc.so.6+0x2e312)

    ​9 0x0000000002b37e2b llvm::ConstantRange::truncate(unsigned int) const /llvm/llvm/lib/IR/ConstantRange.cpp:722:0

    ​10 0x0000000002b3766d llvm::ConstantRange::castOp(llvm::Instruction::CastOps, unsigned int) const /llvm/llvm/lib/IR/ConstantRange.cpp:648:0

    ​11 0x00000000035147ff (anonymous namespace)::SCCPSolver::visitCastInst(llvm::CastInst&) /llvm/llvm/lib/Transforms/Scalar/SCCP.cpp:848:0

    ​12 0x000000000351c99d llvm::InstVisitor<(anonymous namespace)::SCCPSolver, void>::visitTruncInst(llvm::TruncInst&) /llvm/llvm/include/llvm/IR/InstVisitor.h:177:0

    ​13 0x000000000351c1d1 llvm::InstVisitor<(anonymous namespace)::SCCPSolver, void>::visitTrunc(llvm::TruncInst&) /llvm/llvm/include/llvm/IR/Instruction.def:184:0

    ​14 0x000000000351b7db llvm::InstVisitor<(anonymous namespace)::SCCPSolver, void>::visit(llvm::Instruction&) /llvm/llvm/include/llvm/IR/Instruction.def:184:0

    ​15 0x000000000351cef4 void llvm::InstVisitor<(anonymous namespace)::SCCPSolver, void>::visit<llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, false> >(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, false>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, false>) /llvm/llvm/include/llvm/IR/InstVisitor.h:89:0

    ​16 0x000000000351c676 llvm::InstVisitor<(anonymous namespace)::SCCPSolver, void>::visit(llvm::BasicBlock&) /llvm/llvm/include/llvm/IR/InstVisitor.h:106:0

    ​17 0x000000000351baa7 llvm::InstVisitor<(anonymous namespace)::SCCPSolver, void>::visit(llvm::BasicBlock*) /llvm/llvm/include/llvm/IR/InstVisitor.h:111:0

    ​18 0x0000000003517c5f (anonymous namespace)::SCCPSolver::Solve() /llvm/llvm/lib/Transforms/Scalar/SCCP.cpp:1440:0

    ​19 0x0000000003519f66 llvm::runIPSCCP(llvm::Module&, llvm::DataLayout const&, std::function<llvm::TargetLibraryInfo const& (llvm::Function&)>, llvm::function_ref<llvm::AnalysisResultsForFn (llvm::Function&)>) /llvm/llvm/lib/Transforms/Scalar/SCCP.cpp:1969:0

    ​20 0x0000000002f78133 (anonymous namespace)::IPSCCPLegacyPass::runOnModule(llvm::Module&) /llvm/llvm/lib/Transforms/IPO/SCCP.cpp:68:0

    ​21 0x0000000002c9456b (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /llvm/llvm/lib/IR/LegacyPassManager.cpp:1634:0

    ​22 0x0000000002c8fa7d llvm::legacy::PassManagerImpl::run(llvm::Module&) /llvm/llvm/lib/IR/LegacyPassManager.cpp:615:0

    ​23 0x0000000002c94d57 llvm::legacy::PassManager::run(llvm::Module&) /llvm/llvm/lib/IR/LegacyPassManager.cpp:1762:0

    ​24 0x0000000001b4c943 main /llvm/llvm/tools/opt/opt.cpp:1001:0

    ​25 0x00007fe76983fc05 __libc_start_main (/lib64/libc.so.6+0x21c05)

    ​26 0x0000000001b16db9 _start (/bin/opt+0x1b16db9)

    Aborted

fhahn commented 3 years ago

Thanks for the report! Looks like an inconsistency with how vectors with all same constant ranges are bitcasted. Should be fixed with https://reviews.llvm.org/rGd68bed0fa94e