Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang crashes on valid code at -O1 and above on x86_64-linux-gnu: Assertion `N1.getValueType().bitsGT(VT) && "Invalid truncate node, src < dst!"' failed #92720

Closed
zhendongsu opened this issue May 20, 2024 · 2 comments · Fixed by #92753
Assignees
Labels
crash-on-valid llvm:SelectionDAG SelectionDAGISel as well

Comments

@zhendongsu
Copy link

Compiler Explorer: https://godbolt.org/z/vcTf6fxWY

[521] % clangtk -v
clang version 19.0.0git (https://github.com/llvm/llvm-project.git 32ae9a28a54f59f2b4e2f32323f53fb107ea1f85)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /local/suz-local/software/local/clang-trunk/bin
Build config: +assertions
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Candidate multilib: .;@m64
Selected multilib: .;@m64
[522] % 
[522] % clangtk -O1 small.c
clang-19: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:6010: llvm::SDValue llvm::SelectionDAG::getNode(unsigned int, const llvm::SDLoc&, llvm::EVT, llvm::SDValue, llvm::SDNodeFlags): Assertion `N1.getValueType().bitsGT(VT) && "Invalid truncate node, src < dst!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /local/suz-local/software/local/clang-trunk/bin/clang-19 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/local/suz-local/software/emitesting/bugs/20240520-clangtk-m64-O3-build-005835/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20240520-clangtk-m64-O3-build-005835/delta -resource-dir /local/suz-local/software/local/clang-trunk/lib/clang/19 -I /usr/local/include -I /local/suz-local/software/local/include -internal-isystem /local/suz-local/software/local/clang-trunk/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O1 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-09f9be.o -x c small.c
1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module 'small.c'.
4.	Running pass 'X86 DAG->DAG Instruction Selection' on function '@main'
 #0 0x000055d445b3dd8f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x4094d8f)
 #1 0x000055d445b3b2b4 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f2f637c2420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f2f631c900b raise /build/glibc-e2p3jK/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #4 0x00007f2f631a8859 abort /build/glibc-e2p3jK/glibc-2.31/stdlib/abort.c:81:7
 #5 0x00007f2f631a8729 get_sysdep_segment_value /build/glibc-e2p3jK/glibc-2.31/intl/loadmsgcat.c:509:8
 #6 0x00007f2f631a8729 _nl_load_domain /build/glibc-e2p3jK/glibc-2.31/intl/loadmsgcat.c:970:34
 #7 0x00007f2f631b9fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x000055d446d257b1 llvm::SelectionDAG::getNode(unsigned int, llvm::SDLoc const&, llvm::EVT, llvm::SDValue, llvm::SDNodeFlags) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x527c7b1)
 #9 0x000055d446d84024 llvm::TargetLowering::ShrinkDemandedOp(llvm::SDValue, unsigned int, llvm::APInt const&, llvm::TargetLowering::TargetLoweringOpt&) const (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x52db024)
#10 0x000055d446dc3e08 llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x531ae08)
#11 0x000055d446dbd076 llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x5314076)
#12 0x000055d446bb8125 (anonymous namespace)::DAGCombiner::SimplifyDemandedBits(llvm::SDValue) (.constprop.0) DAGCombiner.cpp:0:0
#13 0x000055d446be7d8e (anonymous namespace)::DAGCombiner::visitSIGN_EXTEND_INREG(llvm::SDNode*) DAGCombiner.cpp:0:0
#14 0x000055d446c25fce (anonymous namespace)::DAGCombiner::visit(llvm::SDNode*) DAGCombiner.cpp:0:0
#15 0x000055d446c28541 (anonymous namespace)::DAGCombiner::combine(llvm::SDNode*) DAGCombiner.cpp:0:0
#16 0x000055d446c2a1bc (anonymous namespace)::DAGCombiner::Run(llvm::CombineLevel) DAGCombiner.cpp:0:0
#17 0x000055d446c2c7aa llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOptLevel) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x51837aa)
#18 0x000055d446d63c52 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x52bac52)
#19 0x000055d446d6789d llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x52be89d)
#20 0x000055d446d692d6 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (.part.0) SelectionDAGISel.cpp:0:0
#21 0x000055d444674df0 (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) X86ISelDAGToDAG.cpp:0:0
#22 0x000055d444ec31d1 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#23 0x000055d4454b017b llvm::FPPassManager::runOnFunction(llvm::Function&) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x3a0717b)
#24 0x000055d4454b03c9 llvm::FPPassManager::runOnModule(llvm::Module&) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x3a073c9)
#25 0x000055d4454b0c85 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x3a07c85)
#26 0x000055d445dda723 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) BackendUtil.cpp:0:0
#27 0x000055d445ddab26 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x4331b26)
#28 0x000055d446436dd9 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x498ddd9)
#29 0x000055d4481c0f7c clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x6717f7c)
#30 0x000055d446437268 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x498e268)
#31 0x000055d4466c6f19 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x4c1df19)
#32 0x000055d44664c0ee clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x4ba30ee)
#33 0x000055d4467b1306 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x4d08306)
#34 0x000055d442d191ec cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x12701ec)
#35 0x000055d442d123ea ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#36 0x000055d442d15dbe clang_main(int, char**, llvm::ToolContext const&) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x126cdbe)
#37 0x000055d442c1276b main (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x116976b)
#38 0x00007f2f631aa083 __libc_start_main /build/glibc-e2p3jK/glibc-2.31/csu/../csu/libc-start.c:342:3
#39 0x000055d442d11e7e _start (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x1268e7e)
clangtk: error: unable to execute command: Aborted
clangtk: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 19.0.0git (https://github.com/llvm/llvm-project.git 32ae9a28a54f59f2b4e2f32323f53fb107ea1f85)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /local/suz-local/software/local/clang-trunk/bin
Build config: +assertions
clangtk: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clangtk: note: diagnostic msg: /tmp/small-a04b76.c
clangtk: note: diagnostic msg: /tmp/small-a04b76.sh
clangtk: note: diagnostic msg: 

********************
[523] % 
[523] % cat small.c
long a, b;
static int c;
int main() {
  b = c = a ? a << -(b | 255) : 0;
  return 0;
}
@github-actions github-actions bot added the clang Clang issues not falling into any other category label May 20, 2024
@dtcxzyw
Copy link
Member

dtcxzyw commented May 20, 2024

Reduced IR: https://godbolt.org/z/KTbfnYnET

define i64 @pr92720(i64 %x) {
  %or = or i64 %x, 255
  %sub = sub i64 0, %or
  %shl = shl i64 1, %sub
  %sext = shl i64 %shl, 32
  ret i64 %sext
}

I will post a fix.

@llvmbot
Copy link
Member

llvmbot commented May 20, 2024

@llvm/issue-subscribers-backend-x86

Author: Zhendong Su (zhendongsu)

Compiler Explorer: https://godbolt.org/z/vcTf6fxWY
[521] % clangtk -v
clang version 19.0.0git (https://github.com/llvm/llvm-project.git 32ae9a28a54f59f2b4e2f32323f53fb107ea1f85)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /local/suz-local/software/local/clang-trunk/bin
Build config: +assertions
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Candidate multilib: .;@<!-- -->m64
Selected multilib: .;@<!-- -->m64
[522] % 
[522] % clangtk -O1 small.c
clang-19: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:6010: llvm::SDValue llvm::SelectionDAG::getNode(unsigned int, const llvm::SDLoc&amp;, llvm::EVT, llvm::SDValue, llvm::SDNodeFlags): Assertion `N1.getValueType().bitsGT(VT) &amp;&amp; "Invalid truncate node, src &lt; dst!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /local/suz-local/software/local/clang-trunk/bin/clang-19 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/local/suz-local/software/emitesting/bugs/20240520-clangtk-m64-O3-build-005835/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20240520-clangtk-m64-O3-build-005835/delta -resource-dir /local/suz-local/software/local/clang-trunk/lib/clang/19 -I /usr/local/include -I /local/suz-local/software/local/include -internal-isystem /local/suz-local/software/local/clang-trunk/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O1 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-09f9be.o -x c small.c
1.	&lt;eof&gt; parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module 'small.c'.
4.	Running pass 'X86 DAG-&gt;DAG Instruction Selection' on function '@<!-- -->main'
 #<!-- -->0 0x000055d445b3dd8f llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x4094d8f)
 #<!-- -->1 0x000055d445b3b2b4 SignalHandler(int) Signals.cpp:0:0
 #<!-- -->2 0x00007f2f637c2420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #<!-- -->3 0x00007f2f631c900b raise /build/glibc-e2p3jK/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #<!-- -->4 0x00007f2f631a8859 abort /build/glibc-e2p3jK/glibc-2.31/stdlib/abort.c:81:7
 #<!-- -->5 0x00007f2f631a8729 get_sysdep_segment_value /build/glibc-e2p3jK/glibc-2.31/intl/loadmsgcat.c:509:8
 #<!-- -->6 0x00007f2f631a8729 _nl_load_domain /build/glibc-e2p3jK/glibc-2.31/intl/loadmsgcat.c:970:34
 #<!-- -->7 0x00007f2f631b9fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #<!-- -->8 0x000055d446d257b1 llvm::SelectionDAG::getNode(unsigned int, llvm::SDLoc const&amp;, llvm::EVT, llvm::SDValue, llvm::SDNodeFlags) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x527c7b1)
 #<!-- -->9 0x000055d446d84024 llvm::TargetLowering::ShrinkDemandedOp(llvm::SDValue, unsigned int, llvm::APInt const&amp;, llvm::TargetLowering::TargetLoweringOpt&amp;) const (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x52db024)
#<!-- -->10 0x000055d446dc3e08 llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&amp;, llvm::APInt const&amp;, llvm::KnownBits&amp;, llvm::TargetLowering::TargetLoweringOpt&amp;, unsigned int, bool) const (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x531ae08)
#<!-- -->11 0x000055d446dbd076 llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&amp;, llvm::APInt const&amp;, llvm::KnownBits&amp;, llvm::TargetLowering::TargetLoweringOpt&amp;, unsigned int, bool) const (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x5314076)
#<!-- -->12 0x000055d446bb8125 (anonymous namespace)::DAGCombiner::SimplifyDemandedBits(llvm::SDValue) (.constprop.0) DAGCombiner.cpp:0:0
#<!-- -->13 0x000055d446be7d8e (anonymous namespace)::DAGCombiner::visitSIGN_EXTEND_INREG(llvm::SDNode*) DAGCombiner.cpp:0:0
#<!-- -->14 0x000055d446c25fce (anonymous namespace)::DAGCombiner::visit(llvm::SDNode*) DAGCombiner.cpp:0:0
#<!-- -->15 0x000055d446c28541 (anonymous namespace)::DAGCombiner::combine(llvm::SDNode*) DAGCombiner.cpp:0:0
#<!-- -->16 0x000055d446c2a1bc (anonymous namespace)::DAGCombiner::Run(llvm::CombineLevel) DAGCombiner.cpp:0:0
#<!-- -->17 0x000055d446c2c7aa llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOptLevel) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x51837aa)
#<!-- -->18 0x000055d446d63c52 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x52bac52)
#<!-- -->19 0x000055d446d6789d llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&amp;) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x52be89d)
#<!-- -->20 0x000055d446d692d6 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&amp;) (.part.0) SelectionDAGISel.cpp:0:0
#<!-- -->21 0x000055d444674df0 (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&amp;) X86ISelDAGToDAG.cpp:0:0
#<!-- -->22 0x000055d444ec31d1 llvm::MachineFunctionPass::runOnFunction(llvm::Function&amp;) (.part.0) MachineFunctionPass.cpp:0:0
#<!-- -->23 0x000055d4454b017b llvm::FPPassManager::runOnFunction(llvm::Function&amp;) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x3a0717b)
#<!-- -->24 0x000055d4454b03c9 llvm::FPPassManager::runOnModule(llvm::Module&amp;) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x3a073c9)
#<!-- -->25 0x000055d4454b0c85 llvm::legacy::PassManagerImpl::run(llvm::Module&amp;) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x3a07c85)
#<!-- -->26 0x000055d445dda723 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr&lt;llvm::raw_pwrite_stream, std::default_delete&lt;llvm::raw_pwrite_stream&gt;&gt;, clang::BackendConsumer*) BackendUtil.cpp:0:0
#<!-- -->27 0x000055d445ddab26 clang::EmitBackendOutput(clang::DiagnosticsEngine&amp;, clang::HeaderSearchOptions const&amp;, clang::CodeGenOptions const&amp;, clang::TargetOptions const&amp;, clang::LangOptions const&amp;, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr&lt;llvm::vfs::FileSystem&gt;, std::unique_ptr&lt;llvm::raw_pwrite_stream, std::default_delete&lt;llvm::raw_pwrite_stream&gt;&gt;, clang::BackendConsumer*) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x4331b26)
#<!-- -->28 0x000055d446436dd9 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&amp;) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x498ddd9)
#<!-- -->29 0x000055d4481c0f7c clang::ParseAST(clang::Sema&amp;, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x6717f7c)
#<!-- -->30 0x000055d446437268 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x498e268)
#<!-- -->31 0x000055d4466c6f19 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x4c1df19)
#<!-- -->32 0x000055d44664c0ee clang::CompilerInstance::ExecuteAction(clang::FrontendAction&amp;) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x4ba30ee)
#<!-- -->33 0x000055d4467b1306 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x4d08306)
#<!-- -->34 0x000055d442d191ec cc1_main(llvm::ArrayRef&lt;char const*&gt;, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x12701ec)
#<!-- -->35 0x000055d442d123ea ExecuteCC1Tool(llvm::SmallVectorImpl&lt;char const*&gt;&amp;, llvm::ToolContext const&amp;) driver.cpp:0:0
#<!-- -->36 0x000055d442d15dbe clang_main(int, char**, llvm::ToolContext const&amp;) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x126cdbe)
#<!-- -->37 0x000055d442c1276b main (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x116976b)
#<!-- -->38 0x00007f2f631aa083 __libc_start_main /build/glibc-e2p3jK/glibc-2.31/csu/../csu/libc-start.c:342:3
#<!-- -->39 0x000055d442d11e7e _start (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x1268e7e)
clangtk: error: unable to execute command: Aborted
clangtk: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 19.0.0git (https://github.com/llvm/llvm-project.git 32ae9a28a54f59f2b4e2f32323f53fb107ea1f85)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /local/suz-local/software/local/clang-trunk/bin
Build config: +assertions
clangtk: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clangtk: note: diagnostic msg: /tmp/small-a04b76.c
clangtk: note: diagnostic msg: /tmp/small-a04b76.sh
clangtk: note: diagnostic msg: 

********************
[523] % 
[523] % cat small.c
long a, b;
static int c;
int main() {
  b = c = a ? a &lt;&lt; -(b | 255) : 0;
  return 0;
}

dtcxzyw added a commit that referenced this issue May 22, 2024
…mandedOp` (#92753)

In `TargetLowering::ShrinkDemandedOp`, types of lhs and rhs may differ
before legalization.
In the original case, `VT` is `i64` and `SmallVT` is `i32`, but the type
of rhs is `i8`. Then invalid truncate nodes will be created.

See the description of ISD::SHL for further information:
> After legalization, the type of the shift amount is known to be
TLI.getShiftAmountTy(). Before legalization, the shift amount can be any
type, but care must be taken to ensure it is large enough.


https://github.com/llvm/llvm-project/blob/605ae4e93be8976095c7eedf5c08bfdb9ff71257/llvm/include/llvm/CodeGen/ISDOpcodes.h#L691-L712

This patch stops handling ISD::SHL in `TargetLowering::ShrinkDemandedOp`
and duplicates the logic in `TargetLowering::SimplifyDemandedBits`.
Additionally, it adds some additional checks like
`isNarrowingProfitable` and `isTypeDesirableForOp` to improve the
codegen on AArch64.

Fixes #92720.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment