[llvm-bugs] [Bug 43690] New: LLVM produces redundant IVs and fails to eliminate them

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Oct 16 06:41:24 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=43690

            Bug ID: 43690
           Summary: LLVM produces redundant IVs and fails to eliminate
                    them
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Global Analyses
          Assignee: unassignedbugs at nondot.org
          Reporter: d.maljutin at yandex.ru
                CC: llvm-bugs at lists.llvm.org

Created attachment 22677
  --> https://bugs.llvm.org/attachment.cgi?id=22677&action=edit
Example

It looks like SCEVExpander can create redundant IVs when expanding some SCEV
because
1) It tries to expand SCEV that is identical to that of the IV PHI node, but
the IV is not in a canonical form. The PHI is not reused because it's never
added to ExprToValueMap (only to ValueToExpr), and since it's not in canonical
form (and expander is in canonical mode), it creates additional IV.
I.e. when trying to expand {1,+,1}<nuw><%for.body> with the same IV, it'll
create additional IV {0,+,1}<nuw><%for.body> + add+1 IR instruction.

See the attached IR for such an example.

2) If SCEVExpander is not in canonical mode, it deals with case above, however
it results in the similar problem in the opposite situation, since it doesn't
reuse addrec expressions in non-canonical mode:
https://github.com/llvm/llvm-project/blob/5c3bc3c930d3993a2c5f581112c18a9eb0ba6838/llvm/lib/Analysis/ScalarEvolutionExpander.cpp#L1787

After such redundant IVs are generated, llvm fails to get rid of them (as
demonstrated by running opt -O3 on the attached IR).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191016/c6090abd/attachment.html>


More information about the llvm-bugs mailing list