[PATCH] [IndVarSimplify] Widen loop compares for unsigned IVs that have a uniform step of one.

Ana Pazos apazos at codeaurora.org
Mon Sep 29 15:57:22 PDT 2014


Hi Andy,

I think we are concerned about changing program behavior that somehow might depend/work fine with the wrapping.

Signed arithmetic operations in C standard do not wrap while unsigned arithmetic operations wrap.

So if you have unsigned char a,b and try to add them:
a=255; b = 1;
a+b = 0; // (produces 0 because 256-256=0 and the higher bit is ignored, overflow occurred)

while if you have char a, b when you add them:
a= 127 (0x7F); b= 1;
a+b = -128; // (produces -128 because 128-256=-128,  higher bit is not ignored and flips the sign, overflow occurred)

If we promote an unsigned IV to 64-bit, we believe it has to be done so that it does not change the program behavior.

Example:
for (; i < max_range_for_the_type; i+=d)
  use(i)

In this example what are the safe conditions to promote i to a larger size so that we do not change the program behavior?
Increment/Decrement i by 1 is the only case since it is guaranteed to wrap only when it hits max_range_for_the_type,
while other increment/decrement amounts might skip over the limit and wrap.

So we decided to use SCEV analysis step info to allow widening the unsigned IV only when we are sure we do not change the program behavior.

What do you think?

http://reviews.llvm.org/D5526






More information about the llvm-commits mailing list