[llvm-bugs] [Bug 25060] New: [SCEV] Phi-node backedge is assumed to be at the same index for all phi-nodes in getConstantEvolutionLoopExitValue

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Oct 5 09:18:04 PDT 2015


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

            Bug ID: 25060
           Summary: [SCEV] Phi-node backedge is assumed to be at the same
                    index for all phi-nodes in
                    getConstantEvolutionLoopExitValue
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: mattias.v.eriksson at ericsson.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Created attachment 15006
  --> https://llvm.org/bugs/attachment.cgi?id=15006&action=edit
Reduced input file

Run opt on the attached file like this:

opt -S  -instcombine -licm -sroa -indvars -o t1.ll

Results:

; ModuleID = './t1.ll'

@gi = global i16 0

define i16 @fn3() {
  br label %bb1

bb7:                                              ; preds = %bb2
  %_tmp2 = add i16 %i.9.0, -1
  br label %bb2

bb2:                                              ; preds = %bb2.preheader,
%bb7
  %i.9.0 = phi i16 [ %i.9.1, %bb2.preheader ], [ %_tmp2, %bb7 ]
  %_tmp6 = icmp eq i16 %i.9.0, 0
  br i1 %_tmp6, label %bb4, label %bb7

bb4:                                              ; preds = %bb2
  br label %bb1

bb1:                                              ; preds = %bb4, %0
  %i.9.1 = phi i16 [ 1, %0 ], [ 0, %bb4 ]
  %_tmp10 = icmp eq i16 %i.9.1, 0
  br i1 %_tmp10, label %bb5, label %bb2.preheader

bb2.preheader:                                    ; preds = %bb1
  br label %bb2

bb5:                                              ; preds = %bb1
  store i16 1, i16* @gi, align 2
  ret i16 0

bb6:                                              ; No predecessors!
  ret i16 0
}


The error is that value 1 is stored on the line
  store i16 1, i16* @gi, align 2
The correct value to store is 2.

I have been debugging this and found a problem in ScalarEvolution.cpp:
  // Since the loop is canonicalized, the PHI node must have two entries.  One
  // entry must be a constant (coming in from outside of the loop), and the
  // second must be derived from the same PHI.
  bool SecondIsBackedge = L->contains(PN->getIncomingBlock(1));
  PHINode *PHI = nullptr;
  for (BasicBlock::iterator I = Header->begin();
       (PHI = dyn_cast<PHINode>(I)); ++I) {
    Constant *StartCST =
      dyn_cast<Constant>(PHI->getIncomingValue(!SecondIsBackedge));

Here the code assumes that all phi-nodes have the incoming backedge value at
the same index, but this is not true in this example.

Is this a problem in ScalarEvolution or is the problem already in the input
with badly created phi-nodes?

-- 
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/20151005/93f36eed/attachment.html>


More information about the llvm-bugs mailing list