[llvm] [LV] Improve AnyOf reduction codegen. (PR #78304)

Aleksandr Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 29 09:12:34 PDT 2024


aleks-tmb wrote:

@fhahn Hi, this patch has been reverted, but before it we got a failure in our internal testing.
The reduced IR is:
```llvm
define void @test(i64 %limit, i8 %guard) {
entry:
  br label %pre
pre:                                              ; preds = %loop, %entry
  %iv0 = phi i8 [ 0, %entry ], [ %select, %loop ]
  %cmp = icmp sgt i8 %iv0, %guard
  br label %loop

loop:                                             ; preds = %loop, %pre
  %iv1 = phi i64 [ %iv1.next, %loop ], [ 0, %pre ]
  %iv2 = phi i8 [ %select, %loop ], [ %iv0, %pre ]
  %select = select i1 %cmp, i8 %iv2, i8 0
  %iv1.next = add nuw nsw i64 %iv1, 1
  %check = icmp slt i64 %iv1.next, %limit
  br i1 %check, label %loop, label %pre
}
```
To reproduce, take this patch and run `bin/opt -mtriple=x86_64-unknown-linux-gnu -passes=loop-vectorize test.ll`

The crash backtrace:
```
opt: /home/apopov/llvm-project/llvm/lib/IR/Instructions.cpp:3327: static llvm::BinaryOperator* llvm::BinaryOperator::Create(llvm::Instruction::BinaryOps, llvm::Value*, llvm::Value*, const llvm::Twine&, llvm::Instruction*): Assertion `S1->getType() == S2->getType() && "Cannot create binary operator with two operands of differing type!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: bin/opt -mtriple=x86_64-unknown-linux-gnu -passes=loop-vectorize ../../orca/build/test.ll -S
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  libLLVM.so.19.0git 0x00007f1528cb3fc8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 82
1  libLLVM.so.19.0git 0x00007f1528cb43de
2  libLLVM.so.19.0git 0x00007f1528cb1964 llvm::sys::RunSignalHandlers() + 159
3  libLLVM.so.19.0git 0x00007f1528cb3882
4  libc.so.6          0x00007f1525b91090
5  libc.so.6          0x00007f1525b9100b gsignal + 203
6  libc.so.6          0x00007f1525b70859 abort + 299
7  libc.so.6          0x00007f1525b70729
8  libc.so.6          0x00007f1525b81fd6
9  libLLVM.so.19.0git 0x00007f1528f9b1cb llvm::BinaryOperator::Create(llvm::Instruction::BinaryOps, llvm::Value*, llvm::Value*, llvm::Twine const&, llvm::Instruction*) + 97
10 libLLVM.so.19.0git 0x00007f1528dff294
11 libLLVM.so.19.0git 0x00007f152b5487c1 llvm::VPInstruction::generateInstruction(llvm::VPTransformState&, unsigned int) + 497
12 libLLVM.so.19.0git 0x00007f152b549c12 llvm::VPInstruction::execute(llvm::VPTransformState&) + 290
13 libLLVM.so.19.0git 0x00007f152b4fd82d llvm::VPBasicBlock::execute(llvm::VPTransformState*) + 1079
14 libLLVM.so.19.0git 0x00007f152b4fefd0 llvm::VPRegionBlock::execute(llvm::VPTransformState*) + 616
15 libLLVM.so.19.0git 0x00007f152b4fffdf llvm::VPlan::execute(llvm::VPTransformState*) + 335
16 libLLVM.so.19.0git 0x00007f152b344b3f llvm::LoopVectorizationPlanner::executePlan(llvm::ElementCount, unsigned int, llvm::VPlan&, llvm::InnerLoopVectorizer&, llvm::DominatorTree*, bool, llvm::DenseMap<llvm::SCEV const*, llvm::Value*, llvm::DenseMapInfo<llvm::SCEV const*, void>, llvm::detail::DenseMapPair<llvm::SCEV const*, llvm::Value*>> const*) + 1627
17 libLLVM.so.19.0git 0x00007f152b353822 llvm::LoopVectorizePass::processLoop(llvm::Loop*) + 8712
18 libLLVM.so.19.0git 0x00007f152b354112 llvm::LoopVectorizePass::runImpl(llvm::Function&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::BlockFrequencyInfo*, llvm::TargetLibraryInfo*, llvm::DemandedBits&, llvm::AssumptionCache&, llvm::LoopAccessInfoManager&, llvm::OptimizationRemarkEmitter&, llvm::ProfileSummaryInfo*) + 1118
19 libLLVM.so.19.0git 0x00007f152b354464 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) + 650
20 libLLVM.so.19.0git 0x00007f152d8885a7
21 libLLVM.so.19.0git 0x00007f1529076902 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) + 366
22 libLLVM.so.19.0git 0x00007f152cc20f61
23 libLLVM.so.19.0git 0x00007f1529075b5e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) + 390
24 libLLVM.so.19.0git 0x00007f152cc20e91
25 libLLVM.so.19.0git 0x00007f1529076580 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) + 366
26 opt                0x0000562e2118153c llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) + 6348
27 opt                0x0000562e211531a7 optMain + 6524
28 opt                0x0000562e21150c41 main + 88
29 libc.so.6          0x00007f1525b72083 __libc_start_main + 243
30 opt                0x0000562e21150b2e _start + 46
Aborted
```


https://github.com/llvm/llvm-project/pull/78304


More information about the llvm-commits mailing list