[llvm] [InstCombine] Fold selection between less than zero and one (PR #69961)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 14 01:10:53 PST 2023
elhewaty wrote:
@XChy I tried the following approach.
```
CmpInst::Predicate Pred;
Value *A;
if (match(CondVal,
m_ICmp(Pred, m_Value(A),
m_SpecificInt(A->getType()->getScalarSizeInBits() - 1))) &&
match(TrueVal,
m_LShr(m_Specific(A),
m_SpecificInt(A->getType()->getScalarSizeInBits() - 1))) &&
match(FalseVal, m_One())) {
auto *NewTrue = Builder.CreateICmpSLE(A,
Constant::getNullValue(A->getType()));
replaceOperand(SI, 1, NewTrue);
return new ZExtInst(&SI, SelType);
}
```
but I got this,
````
Stack dump:
0. Program arguments: /media/mohamed/Local-Disk/open-source/New-LLVM/build/bin/opt -S -passes=instcombine
#0 0x0000556c41181420 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/media/mohamed/Local-Disk/open-source/New-LLVM/build/bin/opt+0x2cd0420)
#1 0x0000556c4117e82f llvm::sys::RunSignalHandlers() (/media/mohamed/Local-Disk/open-source/New-LLVM/build/bin/opt+0x2ccd82f)
#2 0x0000556c4117e985 SignalHandler(int) Signals.cpp:0:0
#3 0x00007fd378e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x0000556c40d70b5d llvm::InstCombinerImpl::visitSelectInst(llvm::SelectInst&) InstCombineSelect.cpp:0:0
#5 0x0000556c40c94cec llvm::InstCombinerImpl::run() InstructionCombining.cpp:0:0
#6 0x0000556c40c963ad combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::ProfileSummaryInfo*, unsigned int, bool, llvm::LoopInfo*) InstructionCombining.cpp:0:0
#7 0x0000556c40c97361 llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/media/mohamed/Local-Disk/open-source/New-LLVM/build/bin/opt+0x27e6361)
#8 0x0000556c4138dc66 llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) PassBuilder.cpp:0:0
#9 0x0000556c40b66ce1 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/media/mohamed/Local-Disk/open-source/New-LLVM/build/bin/opt+0x26b5ce1)
#10 0x0000556c413866a6 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) PassBuilder.cpp:0:0
#11 0x0000556c40b659db llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/media/mohamed/Local-Disk/open-source/New-LLVM/build/bin/opt+0x26b49db)
#12 0x0000556c4138d8f6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) PassBuilder.cpp:0:0
#13 0x0000556c40b637c1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/media/mohamed/Local-Disk/open-source/New-LLVM/build/bin/opt+0x26b27c1)
#14 0x0000556c3fae8b35 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/media/mohamed/Local-Disk/open-source/New-LLVM/build/bin/opt+0x1637b35)
#15 0x0000556c3faf809f main (/media/mohamed/Local-Disk/open-source/New-LLVM/build/bin/opt+0x164709f)
#16 0x00007fd378e29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#17 0x00007fd378e29e40 call_init ./csu/../csu/libc-start.c:128:20
#18 0x00007fd378e29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#19 0x0000556c3fadb325 _start (/media/mohamed/Local-Disk/open-source/New-LLVM/build/bin/opt+0x162a325)
Segmentation fault (core dumped)
Traceback (most recent call last):
File "/media/mohamed/Local-Disk/open-source/New-LLVM/llvm-project/llvm/utils/update_test_checks.py", line 327, in <module>
main()
File "/media/mohamed/Local-Disk/open-source/New-LLVM/llvm-project/llvm/utils/update_test_checks.py", line 154, in main
raw_tool_output = common.invoke_tool(
File "/media/mohamed/Local-Disk/open-source/New-LLVM/llvm-project/llvm/utils/UpdateTestChecks/common.py", line 453, in invoke_tool
stdout = subprocess.check_output(
File "/usr/lib/python3.10/subprocess.py", line 421, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/lib/python3.10/subprocess.py", line 526, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '/media/mohamed/Local-Disk/open-source/New-LLVM/build/bin/opt -S -passes=instcombine' returned non-zero exit status 139.
```
https://github.com/llvm/llvm-project/pull/69961
More information about the llvm-commits
mailing list