Skip to content

Loop reroller not able to reroll when the array base address is a derivative of the loop induction variable #19020

Closed as not planned
@llvmbot

Description

@llvmbot
Bugzilla Link 18646
Version trunk
OS Linux
Attachments test.c, test.ll
Reporter LLVM Bugzilla Contributor
CC @hfinkel

Extended Description

The loop reroller is not able to reroll loops of the form where the array base address is a derivative of the loop induction variable.

$ cat test.c
void foo(int *Arr, int n) {
  for (int i = 0; i < n; i += 3) {
     Arr[0]=0;
     Arr[1]=0;
     Arr[2]=0;
     Arr+=3;
   }
}
$ clang -target -arm-none-linux-gnueabi reroll.cpp -S  -O1 -emit-llvm -o test.ll
$ opt -loop-reroll  -S test.ll -debug-only=loop-reroll -stats

This is probably because as the array accesses are not a function of the loop induction variable, which is the loop body form the reroller pass requires.

$ cat test.ll
..
..
for.body:                                         ; preds = %entry, %for.body
  %i.09 = phi i32 [ %add, %for.body ], [ 0, %entry ]
  %Arr.addr.08 = phi i32* [ %add.ptr, %for.body ], [ %Arr, %entry ]
  store i32 0, i32* %Arr.addr.08, align 4, !tbaa !&#8203;1
..
..

The following pattern is successfully rerolled as it satisfies the requirement,

void foo(int *Arr, int n) {
  for (int i = 0; i < n; i += 3) {
     Arr[i]=0;
     Arr[i+1]=0;
     Arr[i+2]=0;
   }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaloopoptimobsoleteIssues with old (unsupported) versions of LLVM

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions