[llvm-commits] [llvm] r119942 - in /llvm/trunk: lib/Analysis/InstructionSimplify.cpp test/Transforms/InstCombine/2010-11-21-SizeZeroTypeGEP.ll

Duncan Sands baldrick at free.fr
Mon Nov 22 02:23:45 PST 2010


Hi Frits,

>> More generally, if a gep index type has size zero, instcombine could replace the
>> index with zero, but that is not done here.
>
> You *could* do that here in certain cases. For instance, if the
> pointer operand is constant and all non-constant indices are over
> zero-sized types you could fold it to a constexpr gep with those
> indices zero (or even a bitcast if all indices are then zero).
>
> Might not be worth it though, as you'd probably still have to
> duplicate pretty much all of that logic in instcombine to handle geps
> with non-constant indices over non-zero-sized types. (And how many
> non-constant indices over zero-sized types are you likely to encounter
> anyway?)

yeah, I don't think it is worth it.  If instcombine modifies indices
for zero sized types, changing them to zero, then if all of the other
indices are constant then the GEP will be constant folded using the
existing logic.  I think this is good enough.

Ciao,

Duncan.



More information about the llvm-commits mailing list