Sanjoy Das
2015-Jan-24 23:54 UTC
[LLVMdev] suspicious code in getPreStartForSignExtend (ScalarEvolution)
In getPreStartForSignExtend (ScalarEvolution.cpp) we have const SCEV *PreStart = SE->getAddExpr(DiffOps, SA->getNoWrapFlags()); If I understand the code correctly, we cannot unconditionally transfer the no-wrap flags from SA to PreStart. "SCEVAddExpr(X, Step, Y) does not signed-overflow" does not imply "SCEVAddExpr(X, Y) does not sign-overflow" [1]. Note: I've assumed that a SCEVAddExpr(a_0, a_1, a_2 ... a_{n-1}) is said to sign-overflow if sext(a_0 + a_1 + a_2 .. a_{n-1}) != sext(a_0) + sext(a_1) + sext(a_2) .. sext(a_{n-1}) Is this correct? This is the only semantics I could think of that makes sense for a commutative operation. -- Sanjoy [1]: e.g. X = INT_SIGNED_MAX, Step = -1, Y = 1
David Majnemer
2015-Jan-25 00:53 UTC
[LLVMdev] suspicious code in getPreStartForSignExtend (ScalarEvolution)
I think your analysis here is spot on. On Sat, Jan 24, 2015 at 3:54 PM, Sanjoy Das <sanjoy at playingwithpointers.com> wrote:> In getPreStartForSignExtend (ScalarEvolution.cpp) we have > > const SCEV *PreStart = SE->getAddExpr(DiffOps, SA->getNoWrapFlags()); > > If I understand the code correctly, we cannot unconditionally transfer > the no-wrap flags from SA to PreStart. "SCEVAddExpr(X, Step, Y) does > not signed-overflow" does not imply "SCEVAddExpr(X, Y) does not > sign-overflow" [1]. > > Note: I've assumed that a SCEVAddExpr(a_0, a_1, a_2 ... a_{n-1}) is > said to sign-overflow if > > sext(a_0 + a_1 + a_2 .. a_{n-1}) != sext(a_0) + sext(a_1) + > sext(a_2) .. sext(a_{n-1}) > > Is this correct? This is the only semantics I could think of that > makes sense for a commutative operation. > > -- Sanjoy > > [1]: e.g. X = INT_SIGNED_MAX, Step = -1, Y = 1 >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150124/7a159022/attachment.html>