For a function TryConvertLoop in pass HardwareLoops, wrong input arguments will
lead to crash. There will be 3 cases.
In line 342, compiler want to get something from
HWLoopInfo.CountType, which depends on if argument Bitwidth is given, if not,
will crash.
In Function isHardwareLoopCandidate, it dereference CountType too.
In Function InsertLoopDec, it dereference LoopDecrement.
They all could lead to crash. This patch add condition to this pass, when we meet unexpected inputs then skip
the pass.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/CodeGen/HardwareLoops.cpp | ||
---|---|---|
330 ↗ | (On Diff #506012) | It shouldn't be possible to trigger an assert when passing arguments to the pass. If there's an invalid combination, it should be handled gracefully, e.g. bailing out without doing anything (together with a debug message perhaps) or using a sane default value if it makes sense. |
llvm/lib/CodeGen/HardwareLoops.cpp | ||
---|---|---|
330 ↗ | (On Diff #506012) | I'm not familiar with this pass so I'm not sure how to correctly handle the unexpected input, maybe someone can refine it later? But for now, the wrong input is unacceptable b/c it will lead to crash. |
llvm/lib/CodeGen/HardwareLoops.cpp | ||
---|---|---|
330 ↗ | (On Diff #506012) | So, hardware-loop-counter-bitwidth defaults to 32. so how about we set the default value of HardwareLoopInfo.CountType to Int32Ty? |
llvm/lib/CodeGen/HardwareLoops.cpp | ||
---|---|---|
330 ↗ | (On Diff #506012) | Sorry, I didn't mean setting it here. struct HardwareLoopInfo is declared in llvm/include/llvm/Analysis/TargetTransformInfo.h, and I think giving the member CountType a default value should work. |
llvm/lib/CodeGen/HardwareLoops.cpp | ||
---|---|---|
330 ↗ | (On Diff #506012) |
Yes, I adjust the code. What I want to point out is that there could be 3 crash situation here, 1 in line 337 in raw file, one in isHardwareLoopCandidate which also use CountType, another in InsertLoopDec which use LoopDecrement. |