[llvm-commits] [llvm] r139450 - /llvm/trunk/lib/Analysis/ScalarEvolution.cpp
Dan Gohman
gohman at apple.com
Mon Nov 28 11:13:00 PST 2011
Hi Andy,
The reason this wasn't done is because of potential trouble with
code like this:
if (some condition which is true when a+b doesn't overflow) {
t0 = add nsw a, b
use(t0);
} else {
t1 = add a, b)
use(t1);
}
Because ScalarEvolution doesn't currently include the nsw flag when
hashing expressions for uniqueness, the nsw flag could get set for
a+b when examining the first add instruction, and remain when that
expression is reused for the second add instruction.
There actually was a comment about this way back in r83649, but
it appears to have gotten lost somewhere along the way.
Dan
On Sep 9, 2011, at 6:09 PM, Andrew Trick wrote:
> Author: atrick
> Date: Fri Sep 9 20:09:50 2011
> New Revision: 139450
>
> URL: http://llvm.org/viewvc/llvm-project?rev=139450&view=rev
> Log:
> Set NSW/NUW flags on SCEVAddExpr when the operation is flagged as
> such.
>
> I'm doing this now for completeness because I can't think of/remember
> any reason that it was left out. I'm not sure it will help anything,
> but if we don't do it we need to explain why in comments.
>
> Modified:
> llvm/trunk/lib/Analysis/ScalarEvolution.cpp
>
> Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=139450&r1=139449&r2=139450&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
> +++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Fri Sep 9 20:09:50 2011
> @@ -3546,7 +3546,13 @@
> AddOps.push_back(Op1);
> }
> AddOps.push_back(getSCEV(U->getOperand(0)));
> - return getAddExpr(AddOps);
> + SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap;
> + OverflowingBinaryOperator *OBO = cast<OverflowingBinaryOperator>(V);
> + if (OBO->hasNoSignedWrap())
> + setFlags(Flags, SCEV::FlagNSW);
> + if (OBO->hasNoUnsignedWrap())
> + setFlags(Flags, SCEV::FlagNUW);
> + return getAddExpr(AddOps, Flags);
> }
> case Instruction::Mul: {
> // See the Add code above.
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list