[llvm-commits] Fold() function on TargetFolder class - removal of redundant constantexpr

Duncan Sands baldrick at free.fr
Wed Feb 23 00:57:41 PST 2011


Hi Jin Gu Kang,

> while processing "kang.temp.e = 1" in TreeToLLVM::EmitLV_COMPONENT_REF() function on llvm-gcc-4.2,
> StructAddrLV.Ptr which is returned from EmitLV() is bitcast ConstantExpr because type of kang's initializer is different
> from type of struct test and this StructAddrLV.Ptr is used as an argument by CreateStructGEP().
> Later, this bitcast ConstantExpr is disappeared by SymbolicallyEvaluateGEP() like above ll code for getelementptr.
>
> so I suggested to keep this bitcast ConstantExpr in order to represent meaning of conversion.

it is true that disabling all constant folding may be helpful for beginners who
want to read the bitcode and understand how it relates to the original C.  This
is not so easy to achieve however because a minimal amount of constant folding
always occurs.  For example you can change llvm-gcc from using TargetFolder to
ConstantFolder.  This will result in less constant folding because it will no
longer use information about the target when constant folding.  However the fold
you mentioned (bitcast turned into deeper GEP) will occur anyway because doing
it does not require knowing the target.  There is also a NoFolder class which
does no folding whatsoever, by creating instructions rather than constants, but
I hear that it doesn't work anymore (it used to, but perhaps bitrotted because
no one uses it).  If you want to disable all constant folding in llvm-gcc then
I suggest you change all instances of TargetFolder to NoFolder in
llvm-internal.h and llvm-backend.cpp.  This line
   TheFolder = new TargetFolder(TheTarget->getTargetData());
probably needs to become something like this:
   TheFolder = new NoFolder(getGlobalContext());
However as I mentioned it probably will require some work on IRBuilder and
NoFolder to get it working properly.  If you succeed please send in a patch.

Ciao, Duncan.



More information about the llvm-commits mailing list