OSDN Git Service

[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)
commit75d009930b5491f8c0194112883ca7a58e3353f5
tree9a3dac8bf0b3ab7ae8946a7d0d69db27fb619714
parent6ad6c513ee5746840b4183c93faae89cafd5dacb
[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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286969 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Vectorize/LoopVectorize.cpp
test/Transforms/LoopVectorize/X86/reg-usage-debug.ll [new file with mode: 0644]
test/Transforms/LoopVectorize/X86/reg-usage.ll