[llvm-commits] Fold() function on TargetFolder class - removal of redundant constantexpr
Jin Gu Kang
jaykang10 at imrc.kist.re.kr
Tue Feb 22 01:07:33 PST 2011
OK. I unstand :)
I send modified patch
Index: include/llvm/Support/TargetFolder.h
===================================================================
--- include/llvm/Support/TargetFolder.h (revision 126080)
+++ include/llvm/Support/TargetFolder.h (working copy)
@@ -34,8 +34,12 @@
/// 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)
+ if (CE->use_empty())
+ CE->destroyConstant();
return CF;
+ }
return C;
}
________________________________________
From: Duncan Sands [baldrick at free.fr]
Sent: Tuesday, February 22, 2011 5:57 PM
To: Jin Gu Kang
Subject: Re: [llvm-commits] Fold() function on TargetFolder class - removal of redundant constantexpr
> Argument of Fold() is as follows:
> file: include/llvm/Support/TargetFolder.h on llvm-2.8
> Constant *CreateInBoundsGetElementPtr(Constant *C, Value* const *IdxList,
> unsigned NumIdx) const {
> return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx));
> }
>
> Newly made ConstantExpr is argument of Fold() function.
It may not really be new, that's the point.
Ciao, Duncan.
> --> ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx)
> so if Fold() function make new folded ConstantExpr, I think
> previous created ConstantExpr is redundant.
>
> ________________________________________
> From: llvm-commits-bounces at cs.uiuc.edu [llvm-commits-bounces at cs.uiuc.edu] On Behalf Of Duncan Sands [baldrick at free.fr]
> Sent: Tuesday, February 22, 2011 5:35 PM
> To: llvm-commits at cs.uiuc.edu
> Subject: Re: [llvm-commits] Fold() function on TargetFolder class - removal of redundant constantexpr
>
> 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.
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Fold_Patch
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110222/4d199dd0/attachment.ksh>
More information about the llvm-commits
mailing list