[LLVMdev] Opt pass 'Canonicalize Induction Variables' not working

Pieter Custers pieterjjmcusters at gmail.com
Mon Jan 16 04:19:47 PST 2012


I am new to LLVM and I've a question about the optimization passes and in particular about the loop transformation passes. I've setup the LLVM tool-chain with Polly installed.

The following example is causing problems with me: http://llvm.org/docs/Passes.html#indvars

The input is a .c file with the following loops:

# 01 Standard, N=100
for (i=0; i<N; i++)
	b[i] = a[i] + 5;

# 02 Example loop -indvars
for (i = 7; i*i < 1000; ++i)
	b[i] = 4;

# 03 Start at 1 instead of 0
for (i = 1; i<10; i++)
	b[i] = 3;

I have the latest LLVM build installed on Mac OSX 10.6.8.

A script with (among others) the following lines is used:

-----------------------------------------------------------------------------------------------------
POLLY_DLIB=/Developer/llvm_build/tools/polly/Debug+Asserts/lib/LLVMPolly.dylib
alias opt="/Developer/llvm_build/Debug+Asserts/bin/opt -load ${POLLY_DLIB}"
alias llvm-as="/Developer/llvm_build/Debug+Asserts/bin/llvm-as"

# Set input filename
FILE="indvar"

# Run clang to generate LLVM-IR
clang -S -emit-llvm ${FILE}.c -o ${FILE}.s

# Make the human readable format into bitcode format
llvm-as ${FILE}.s -o ${FILE}.bc

# Prepare the LLVM-Bytecode into canonical form
opt -S -mem2reg -loop-simplify -indvars ${FILE}.bc > ${FILE}.ll
-----------------------------------------------------------------------------------------------------


What I want (and what is not working) is that loop 2 and loop 3 are transformed into a loop starting at 0 with stride 1 (natural loop). Subsequent passes need this to output information to form a Polyhedral model (PHM).

Up to now, only the first loop is recognized as natural loop (as it already is one) and information about the loop is outputted as PHM. The other two loops aren't changed.

Can somebody give me some advise? Maybe I'm using the wrong passes or in the wrong order? 

Many thanks in advance,

Pieter


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120116/94ca2b40/attachment.html>


More information about the llvm-dev mailing list