[llvm] r210439 - [SeparateConstOffsetFromGEP] Fix an illegitimate optimization on zext
Jingyue Wu
jingyue at google.com
Sun Jun 8 13:44:11 PDT 2014
Hi David,
I am unable to trigger this bug because ZeroExtended and NonNegative cannot
be both true given the current logic. However, theoretically it is still a
bug.
Jingyue
On Sun, Jun 8, 2014 at 1:37 PM, David Blaikie <dblaikie at gmail.com> wrote:
> Test coverage?
>
> On Sun, Jun 8, 2014 at 1:19 PM, Jingyue Wu <jingyue at google.com> wrote:
> > Author: jingyue
> > Date: Sun Jun 8 15:19:38 2014
> > New Revision: 210439
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=210439&view=rev
> > Log:
> > [SeparateConstOffsetFromGEP] Fix an illegitimate optimization on zext
> >
> > zext(a + b) != zext(a) + zext(b) even if a + b >= 0 && b >= 0.
> >
> > e.g., a = i4 0b1111, b = i4 0b0001
> > zext a + b to i8 = zext 0b0000 to i8 = 0b00000000
> > (zext a to i8) + (zext b to i8) = 0b00001111 + 0b00000001 = 0b00010000
> >
> > Modified:
> > llvm/trunk/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
> >
> > Modified: llvm/trunk/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp?rev=210439&r1=210438&r2=210439&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
> (original)
> > +++ llvm/trunk/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp Sun
> Jun 8 15:19:38 2014
> > @@ -321,9 +321,9 @@ bool ConstantOffsetExtractor::CanTraceIn
> > // 1 | 0 | sext(BO) == sext(A) op sext(B)
> > // 1 | 1 | zext(sext(BO)) ==
> > // | | zext(sext(A)) op zext(sext(B))
> > - if (BO->getOpcode() == Instruction::Add && NonNegative) {
> > + if (BO->getOpcode() == Instruction::Add && !ZeroExtended &&
> NonNegative) {
> > // If a + b >= 0 and (a >= 0 or b >= 0), then
> > - // s/zext(a + b) = s/zext(a) + s/zext(b)
> > + // sext(a + b) = sext(a) + sext(b)
> > // even if the addition is not marked nsw.
> > //
> > // Leveraging this invarient, we can trace into an sext'ed inbound
> GEP
> >
> >
> > _______________________________________________
> > 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/20140608/5fa1f2e8/attachment.html>
More information about the llvm-commits
mailing list