[llvm-commits] [llvm] r124368 - in /llvm/trunk: lib/Transforms/IPO/MergeFunctions.cpp test/Transforms/MergeFunc/vector.ll
Nick Lewycky
nlewycky at google.com
Thu Jan 27 11:57:45 PST 2011
On 27 January 2011 10:11, Chris Lattner <clattner at apple.com> wrote:
> On Jan 27, 2011, at 12:38 AM, Nick Lewycky wrote:
> > URL: http://llvm.org/viewvc/llvm-project?rev=124368&view=rev
> > Log:
> > Fix surprising missed optimization in mergefunc where we forgot to
> consider
> > that relationships like "i8* null" is equivalent to "i32* null".
>
> Nice!
>
> > +++ llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp Thu Jan 27 02:38:19
> 2011
> > @@ -460,9 +460,18 @@
>
> > + if (isa<Constant>(V1)) {
> > + if (V1 == V2) return true;
> > + const Constant *C1 = cast<Constant>(V1);
>
> Please use dyn_cast in the if instead of isa+cast.
>
Done.
> > + const Constant *C2 = dyn_cast<Constant>(V2);
> > + if (!C2) return false;
> > + // TODO: constant expressions with GEP or references to F1 or F2.
> > + if (C1->isNullValue() && C2->isNullValue() &&
> > + isEquivalentType(C1->getType(), C2->getType()))
> > + return true;
>
> isEquivalentType accepts intptr_t and void* as equiv, so this will merge
> null with (intptr)0 right?
>
Right.
> + return C1->getType()->canLosslesslyBitCastTo(C2->getType()) &&
> > + C1 == ConstantExpr::getBitCast(const_cast<Constant*>(C2),
> C1->getType());
> > + }
>
> Urr? What is this about? This needs a comment at the very least.
>
I've added a comment. The only case this doesn't handle is inttoptr/ptrtoint
conversions (since you can't bitcast integers and pointers), which are
special-cased for null-only above. I may want to generalize that test too.
While we're at it, I should probably also call
ConstantFoldConstantExpression on it given that I have a TD and ConstantExpr
doesn't. I didn't think it was worth thinking about this comparison function
too hard, but maybe I'll try it and see whether it improves the number of
merges in llvm-test.
Nick
>
> -Chris
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110127/579aafae/attachment.html>
More information about the llvm-commits
mailing list