[LLVMbugs] [Bug 15205] New: Unable to detect loop entry guard with ScalarEvolution

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Feb 7 15:57:08 PST 2013


            Bug ID: 15205
           Summary: Unable to detect loop entry guard with ScalarEvolution
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Global Analyses
          Assignee: unassignedbugs at nondot.org
          Reporter: michele.scandale at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Using ScalarEvolution in custom pass run on the IR at the end of all standard
optimization, in the following case ScalarEvolution do not recognize that the
loop has an entry guard related to the initial value of its induction variable.

The C test case:
extern void x(int);

int foo_int(int a, int b) {
  int i;
  for (i = 0; i < b/2; ++i) {

  return 0;

the correspondent optimized IR is:

define i32 @foo_int(i32 %a, i32 %b) nounwind uwtable {
  %div = sdiv i32 %b, 2
  %cmp3 = icmp sgt i32 %b, 1
  br i1 %cmp3, label %for.body, label %for.end

for.body:                                         ; preds = %entry, %for.body
  %i.04 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
  tail call void @x(i32 %i.04) nounwind
  %inc = add nsw i32 %i.04, 1
  %cmp = icmp slt i32 %inc, %div
  br i1 %cmp, label %for.body, label %for.end

for.end:                                          ; preds = %for.body, %entry
  ret i32 0

>From the IR is possible to see that the condition in the entry block is

  %cmp3 = icmp sgt i32 %b, 1

but starting from the loop IV it should be expected something like

  %cmp3 = icmp slt i32 0, %div

and this is verified looking at the instcombine debug trace:
IC: Visiting:   %cmp3 = icmp slt i32 0, %div
IC: Old =   %cmp3 = icmp sgt i32 %div, 0
    New =   <badref> = icmp sge i32 %b, 2
IC: ADD:   %cmp3 = icmp sge i32 %b, 2
IC: ERASE   %0 = icmp sgt i32 %div, 0
IC: ADD:   %div = sdiv i32 %b, 2
IC: Visiting:   %div = sdiv i32 %b, 2
IC: Visiting:   %cmp3 = icmp sge i32 %b, 2
IC: Old =   %cmp3 = icmp sge i32 %b, 2
    New =   <badref> = icmp sgt i32 %b, 1
IC: ADD:   %cmp3 = icmp sgt i32 %b, 1
IC: ERASE   %0 = icmp sge i32 %b, 2

After InstCombine pass ScalarEvolution is no more able to detect the entry
guard of the loop.

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/20130207/ab7a32fb/attachment.html>

More information about the llvm-bugs mailing list