TurnSwitchRangeIntoICmp crashes when given a switch with a default destination of unreachable
Addresses issue #53208
https://github.com/llvm/llvm-project/issues/53208
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
can you put the bug number (e.g. #12345) in the description?
llvm/lib/Transforms/Utils/SimplifyCFG.cpp | ||
---|---|---|
5190 | destination | |
5222 | this comment makes it sound like at this point your comment is always true | |
5223 | LLVM style is no braces for a one line if | |
llvm/test/Transforms/SimplifyCFG/switch-default-undef.ll | ||
1 | can you use llvm/utils/update_test_checks.py? |
Nice!
llvm/lib/Transforms/Utils/SimplifyCFG.cpp | ||
---|---|---|
5222 | Also, should it be "unreachable" rather than "undef"? | |
llvm/test/Transforms/SimplifyCFG/switch-default-undef.ll | ||
1 | Instead of creating a new file, could you add this as a test case to llvm/test/Transforms/SimplifyCFG/switch-range-to-icmp.ll instead? | |
9 | In this switch, the default destination doesn't look unreachable. Is it made unreachable by some other transformation that happens before TurnSwitchRangeIntoICmp()? Can you make the test show the input that TurnSwitchRangeIntoICmp operates on directly? |
Updating D127712: Prevent crash when TurnSwitchRangeIntoICmp recieves default null dest
llvm/test/Transforms/SimplifyCFG/switch-default-undef.ll | ||
---|---|---|
9 | It is made unreachable by some other transformation. switch i8 %sw, label %unreachable [ i8 10, label %group2 i8 9, label %group2 ] |
It looks like you only uploaded the diff to the previous version, rather than the whole patch.
Updating D127712: Prevent crash when TurnSwitchRangeIntoICmp receives default unreachable destination
llvm/lib/Transforms/Utils/SimplifyCFG.cpp | ||
---|---|---|
5228 | As this assert indicates, this case was supposed to be handled earlier already, namely by the ConstantFoldTerminator call. The reason it doesn't handle it is that https://github.com/llvm/llvm-project/blob/4c2bccfda3892ae13e97b6bfdbc99ec8cf5d095d/llvm/lib/Transforms/Utils/Local.cpp#L194-L198 will pick the unreachable block as the "only dest" and eliminate all unreachable cases. But that then leaves us with the actual only destination, which would get folded by a second call to ConstantFoldTerminator. Possibly the function should be improved to always find the non-unreachable dest. But in any case, adding a conservative bailout here is reasonable, though the assertion message here is a bit outdated. | |
llvm/test/Transforms/SimplifyCFG/switch-range-to-icmp.ll | ||
150 ↗ | (On Diff #437078) | Please give this function a name (like pr53208_single_reachable_dest or something). |
llvm/lib/Transforms/Utils/SimplifyCFG.cpp | ||
---|---|---|
5228 | It looks like this is optimized after anyways, but yeah ideally it shouldn't get to this point in the first place. |
destination