[LoopVectorizer] When estimating reg usage, unused insts may "end" another use
authorRobert Lougher <rob.lougher@gmail.com>
Tue, 15 Nov 2016 14:27:33 +0000 (14:27 +0000)
committerRobert Lougher <rob.lougher@gmail.com>
Tue, 15 Nov 2016 14:27:33 +0000 (14:27 +0000)
commitb0905209ddebaa01cf7d4fc24618f4ec137988ca
tree2f742f8b129576d6b5b5b029c9424bb35d27cd99
parent5f850cd1b10f4dffc86285c2f71ab34cba9e929d
[LoopVectorizer] When estimating reg usage, unused insts may "end" another use

The register usage algorithm incorrectly treats instructions whose value is
not used within the loop (e.g. those that do not produce a value).

The algorithm first calculates the usages within the loop.  It iterates over
the instructions in order, and records at which instruction index each use
ends (in fact, they're actually recorded against the next index, as this is
when we want to delete them from the open intervals).

The algorithm then iterates over the instructions again, adding each
instruction in turn to a list of open intervals.  Instructions are then
removed from the list of open intervals when they occur in the list of uses
ended at the current index.

The problem is, instructions which are not used in the loop are skipped.
However, although they aren't used, the last use of a value may have been
recorded against that instruction index.  In this case, the use is not deleted
from the open intervals, which may then bump up the estimated register usage.

This patch fixes the issue by simply moving the "is used" check after the loop
which erases the uses at the current index.

Differential Revision: https://reviews.llvm.org/D26554

llvm-svn: 286969
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/test/Transforms/LoopVectorize/X86/reg-usage-debug.ll [new file with mode: 0644]
llvm/test/Transforms/LoopVectorize/X86/reg-usage.ll