I'm trying to find reduction variables in a loop and I have a couple of questions about it.
Is it necessary that a reduction variable should be associated with a Phi node?
For my purpose, I tried using isReductionPHI() from LoopUtils.cpp (that is used by LoopVectorizer) for a toy C program (find below) that has a clear reduction variable but it still returns false.
// Toy program where "sum" is the reduction variable.
#include <stdio.h>intmain(int argc, charconst*argv)
int sum =0, a, i;
for(i =0; i <100; i++)
sum += a[i];
printf("sum: %d\n", sum);
I generated LLVM IR (toy_reduction.ll) for the above program and then applied mem2reg on top of it (toy_reduction_mem2reg.ll). I have implemented a toy analysis pass which prints the phi nodes that are associated with reduction variables which is as under.
However, for the input file toy_reduction_mem2reg.ll, isReductionPHI() returns false every time the control reaches there thereby declaring that there are no reduction variables when clearly there is one (sum).
Find below a snippet of the LLVM IR after applying mem2reg.