Open weiguozhi opened 7 years ago
Compile the following code with options
--target=powerpc64le-grtev4-linux-gnu -m64 -O2 -mvsx -mcpu=power8
extern void bar(int);
void foo(const int* p, int n) { for (int j = 0; j < n; ++j) { int k = p[j]; bar(k); } }
I got:
clrldi 30, 4, 32 addi 4, 3, -4 .p2align 5
.LBB0_2: # %for.body
lwa 3, 4(4) addi 29, 4, 4 bl _Z3bari nop addi 30, 30, -1 mr 4, 29 cmpldi 30, 0 bne 0, .LBB0_2
Var j is an induction variable, it is only used to index an array, so it can be optimized away, like following
clrldi 30, 4, 32 sldi 30, 30, 2 // * add 30, 30, 4 // * addi 4, 3, -4 .p2align 5
lwa 3, 4(4) addi 29, 4, 4 bl _Z3bari nop
// addi 30, 30, -1 mr 4, 29 cmpld 30, 29 // * bne 0, .LBB0_2
add 30, 30, 4 // *
should be
add 30, 30, 3 // *
Extended Description
Compile the following code with options
--target=powerpc64le-grtev4-linux-gnu -m64 -O2 -mvsx -mcpu=power8
extern void bar(int);
void foo(const int* p, int n) { for (int j = 0; j < n; ++j) { int k = p[j]; bar(k); } }
I got:
.LBB0_2: # %for.body
=>This Inner Loop Header: Depth=1
Var j is an induction variable, it is only used to index an array, so it can be optimized away, like following
.LBB0_2: # %for.body
=>This Inner Loop Header: Depth=1
// addi 30, 30, -1
mr 4, 29 cmpld 30, 29 // * bne 0, .LBB0_2