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

Duncan Sands baldrick at free.fr
Tue Feb 22 00:35:55 PST 2011


Hi Jin Gu Kang,

> --- include/llvm/Support/TargetFolder.h (revision 126080)
> +++ include/llvm/Support/TargetFolder.h (working copy)
> @@ -34,8 +34,11 @@
> /// Fold - Fold the constant using target specific information.
> Constant *Fold(Constant *C) const {
> if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
> - if (Constant *CF = ConstantFoldConstantExpression(CE, TD))
> + if (Constant *CF = ConstantFoldConstantExpression(CE, TD)) {
> + if (CF != CE)
> + CE->destroyConstant();

this is wrong.  Constants are global and uniqued: if someone creates a constant,
eg: 27, any later attempt to create an identical constant (27) returns the same
constant as was created earlier, not a new one.  This means that you can check
if constants are identical by comparing their pointer values.  It also means
that you can't free a constant like your patch does without first proving that
it is not being used anywhere.

Ciao, Duncan.



More information about the llvm-commits mailing list