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

Jin Gu Kang jaykang10 at imrc.kist.re.kr
Tue Feb 22 00:22:10 PST 2011


Hi llvm-commits members

I think Fold() function on TargetFolder class is only called when creating constant expression.

When return value 'Constant *CF' from ConstantFoldConstantExpression() function on Fold()
is different from argument 'CE', argument 'CE' is old and redundant and this 'CE' increases
use count of its operands.

so I think redundant 'CE' has to be removed as follows:

Index: include/llvm/Support/TargetFolder.h
===================================================================
--- 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();
         return CF;
+     }
     return C;
   }



Please review the attached patch.

Thank you,
Jin-Gu Kang

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110222/ad7d797b/attachment.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Fold_Patch
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110222/ad7d797b/attachment.ksh>


More information about the llvm-commits mailing list