Do not allow switch statements in loop latches
authorTobias Grosser <tobias@grosser.es>
Thu, 10 Nov 2016 05:20:29 +0000 (05:20 +0000)
committerTobias Grosser <tobias@grosser.es>
Thu, 10 Nov 2016 05:20:29 +0000 (05:20 +0000)
commitbbaeda3fe5d132d4b58f7606663704e408ef9796
tree55b4e5ebace51ff25d0f4b50b1a3aa95753edbb1
parent924c5ec472a31be66d4d0b9f5c2b92b0b0102fec
Do not allow switch statements in loop latches

In r248701 "Allow switch instructions in SCoPs" support for switch statements
has been introduced, but support for switch statements in loop latches was
incomplete. This change completely disables switch statements in loop latches.

The original commit changed addLoopBoundsToHeaderDomain to support non-branch
terminator instructions, but this change was incorrect: it added a check for
BI != null to the if-branch of a condition, but BI was used in the else branch
es well. As a result, when a non-branch terminator instruction is encounted a
nullptr dereference is triggered. Due to missing test coverage, this bug was
overlooked.

r249273 "[FIX] Approximate non-affine loops correctly" added code to disallow
switch statements for non-affine loops, if they appear in either a loop latch
or a loop exit. We adapt this code to now prohibit switch statements in
loop latches even if the control condition is affine.

We could possibly add support for switch statements in loop latches, but such
support should be evaluated and tested separately.

This fixes llvm.org/PR30952

Reported-by: Eli Friedman <efriedma@codeaurora.org>
llvm-svn: 286426
polly/lib/Analysis/ScopDetection.cpp
polly/lib/Analysis/ScopInfo.cpp
polly/test/ScopDetect/switch-in-loop-patch.ll [new file with mode: 0644]