[llvm] [LoongArch] Remove spurious mask operations from andn->icmp on 16 and 8 bit values (PR #99272)
Nathan Chancellor via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 20 17:21:14 PDT 2024
nathanchance wrote:
This change causes some assertion failures when building the Linux kernel. A C reproducer from `cvise` and LLVM IR reproducer from `llvm-reduce`:
```c
struct vdpa_config_ops {
char (*get_status)(int *);
} vhost_vdpa_set_status_v_1_0;
unsigned char vhost_vdpa_set_status_status, vhost_vdpa_set_status_status_old;
int vhost_vdpa_set_status_vdpa;
long vhost_vdpa_set_status() {
struct vdpa_config_ops ops = vhost_vdpa_set_status_v_1_0;
vhost_vdpa_set_status_status_old =
ops.get_status(&vhost_vdpa_set_status_vdpa);
if (vhost_vdpa_set_status_status &&
vhost_vdpa_set_status_status_old & ~vhost_vdpa_set_status_status)
return 2;
return 0;
}
```
```
$ clang --target=loongarch64 -O2 -c -o /dev/null vdpa.i
clang: /home/nathan/tmp/cvise.LNRIE3dN98/src/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:6936: SDValue llvm::SelectionDAG::getNode(unsigned int, const SDLoc &, EVT, SDValue, SDValue, const SDNodeFlags): Assertion `N1.getValueType() == N2.getValueType() && N1.getValueType() == VT && "Binary operator types must match!"' 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: clang --target=loongarch64 -O2 -c -o /dev/null vdpa.i
1. <eof> parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module 'vdpa.i'.
4. Running pass 'LoongArch DAG->DAG Pattern Instruction Selection' on function '@vhost_vdpa_set_status'
#0 0x0000564a17a4de26 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x55f5e26)
#1 0x0000564a17a4b8ee llvm::sys::RunSignalHandlers() (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x55f38ee)
#2 0x0000564a179ced8d CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007f803d691ae0 (/usr/lib/libc.so.6+0x3cae0)
#4 0x00007f803d6e9e44 (/usr/lib/libc.so.6+0x94e44)
#5 0x00007f803d691a30 raise (/usr/lib/libc.so.6+0x3ca30)
#6 0x00007f803d6794c3 abort (/usr/lib/libc.so.6+0x244c3)
#7 0x00007f803d6793df (/usr/lib/libc.so.6+0x243df)
#8 0x00007f803d689c67 (/usr/lib/libc.so.6+0x34c67)
#9 0x0000564a18d056e1 llvm::SelectionDAG::getNode(unsigned int, llvm::SDLoc const&, llvm::EVT, llvm::SDValue, llvm::SDValue, llvm::SDNodeFlags) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x68ad6e1)
#10 0x0000564a16b7f4a9 llvm::LoongArchTargetLowering::PerformDAGCombine(llvm::SDNode*, llvm::TargetLowering::DAGCombinerInfo&) const LoongArchISelLowering.cpp:0:0
#11 0x0000564a18b7c562 (anonymous namespace)::DAGCombiner::combine(llvm::SDNode*) DAGCombiner.cpp:0:0
#12 0x0000564a18b7ae30 llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOptLevel) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x6722e30)
#13 0x0000564a18d40de5 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x68e8de5)
#14 0x0000564a18d3f9e6 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x68e79e6)
#15 0x0000564a18d3cd48 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x68e4d48)
#16 0x0000564a18d3a686 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x68e2686)
#17 0x0000564a16fbe112 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x4b66112)
#18 0x0000564a175474b6 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x50ef4b6)
#19 0x0000564a1754fd42 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x50f7d42)
#20 0x0000564a17547f92 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x50eff92)
#21 0x0000564a182881de 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*) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x5e301de)
#22 0x0000564a182ae567 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x5e56567)
#23 0x0000564a19736e09 clang::ParseAST(clang::Sema&, bool, bool) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x72dee09)
#24 0x0000564a1874039d clang::FrontendAction::Execute() (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x62e839d)
#25 0x0000564a186a4abd clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x624cabd)
#26 0x0000564a1881c74c clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x63c474c)
#27 0x0000564a15ab288a cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x365a88a)
#28 0x0000564a15aaeedd ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#29 0x0000564a184ca549 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::$_0>(long) Job.cpp:0:0
#30 0x0000564a179ceac6 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x5576ac6)
#31 0x0000564a184c9be3 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x6071be3)
#32 0x0000564a184817d7 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x60297d7)
#33 0x0000564a18481d37 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x6029d37)
#34 0x0000564a184a4499 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x604c499)
#35 0x0000564a15aae37d clang_main(int, char**, llvm::ToolContext const&) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x365637d)
#36 0x0000564a15abfe86 main (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x3667e86)
#37 0x00007f803d67ac88 (/usr/lib/libc.so.6+0x25c88)
#38 0x00007f803d67ad4c __libc_start_main (/usr/lib/libc.so.6+0x25d4c)
#39 0x0000564a15aac7a5 _start (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/clang-19+0x36547a5)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
```
```llvm
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
target triple = "loongarch64"
define i64 @vhost_vdpa_set_status() #0 {
entry:
%call = tail call signext i8 null(ptr null)
%0 = load i8, ptr null, align 1
%tobool.not = icmp eq i8 %0, 0
br i1 %tobool.not, label %if.end, label %land.lhs.true
land.lhs.true: ; preds = %entry
%conv = zext i8 %0 to i32
%conv1 = zext i8 %call to i32
%not = xor i32 %conv, -1
%and = and i32 %not, %conv1
%tobool3.not = icmp eq i32 %and, 0
br i1 %tobool3.not, label %if.end, label %cleanup
if.end: ; preds = %land.lhs.true, %entry
br label %cleanup
cleanup: ; preds = %if.end, %land.lhs.true
%retval.0 = phi i64 [ 0, %if.end ], [ 1, %land.lhs.true ]
ret i64 %retval.0
}
attributes #0 = { "target-features"="+64bit,+d,+f,+ual" }
```
```
$ llc -o /dev/null reduced.ll
llc: /home/nathan/tmp/cvise.LNRIE3dN98/src/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:6936: SDValue llvm::SelectionDAG::getNode(unsigned int, const SDLoc &, EVT, SDValue, SDValue, const SDNodeFlags): Assertion `N1.getValueType() == N2.getValueType() && N1.getValueType() == VT && "Binary operator types must match!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: llc -o /dev/null reduced.ll
1. Running pass 'Function Pass Manager' on module 'reduced.ll'.
2. Running pass 'LoongArch DAG->DAG Pattern Instruction Selection' on function '@vhost_vdpa_set_status'
#0 0x00005582bdd15566 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/llc+0x5192566)
#1 0x00005582bdd12fbe llvm::sys::RunSignalHandlers() (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/llc+0x518ffbe)
#2 0x00005582bdd15c74 SignalHandler(int) Signals.cpp:0:0
#3 0x00007f13857cbae0 (/usr/lib/libc.so.6+0x3cae0)
#4 0x00007f1385823e44 (/usr/lib/libc.so.6+0x94e44)
#5 0x00007f13857cba30 raise (/usr/lib/libc.so.6+0x3ca30)
#6 0x00007f13857b34c3 abort (/usr/lib/libc.so.6+0x244c3)
#7 0x00007f13857b33df (/usr/lib/libc.so.6+0x243df)
#8 0x00007f13857c3c67 (/usr/lib/libc.so.6+0x34c67)
#9 0x00005582bdac5311 llvm::SelectionDAG::getNode(unsigned int, llvm::SDLoc const&, llvm::EVT, llvm::SDValue, llvm::SDValue, llvm::SDNodeFlags) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/llc+0x4f42311)
#10 0x00005582bc6a80f9 llvm::LoongArchTargetLowering::PerformDAGCombine(llvm::SDNode*, llvm::TargetLowering::DAGCombinerInfo&) const LoongArchISelLowering.cpp:0:0
#11 0x00005582bd904ee2 (anonymous namespace)::DAGCombiner::combine(llvm::SDNode*) DAGCombiner.cpp:0:0
#12 0x00005582bd9037b0 llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOptLevel) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/llc+0x4d807b0)
#13 0x00005582bdb03675 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/llc+0x4f80675)
#14 0x00005582bdb02276 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/llc+0x4f7f276)
#15 0x00005582bdaff5d8 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/llc+0x4f7c5d8)
#16 0x00005582bdafcf16 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/llc+0x4f79f16)
#17 0x00005582bcd5ecf2 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/llc+0x41dbcf2)
#18 0x00005582bd2bbe76 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/llc+0x4738e76)
#19 0x00005582bd2c47e2 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/llc+0x47417e2)
#20 0x00005582bd2bc9e2 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/llc+0x47399e2)
#21 0x00005582bb6f6972 main (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/llc+0x2b73972)
#22 0x00007f13857b4c88 (/usr/lib/libc.so.6+0x25c88)
#23 0x00007f13857b4d4c __libc_start_main (/usr/lib/libc.so.6+0x25d4c)
#24 0x00005582bb6f08a5 _start (/home/nathan/tmp/cvise.LNRIE3dN98/install/llvm-bad/bin/llc+0x2b6d8a5)
```
https://github.com/llvm/llvm-project/pull/99272
More information about the llvm-commits
mailing list