Haicheng Wu via llvm-dev
2016-Mar-03 22:06 UTC
[llvm-dev] Failure to turn a div by power of 2 into a single shift
Hello, I have a simple loop like below int I, j; for (j = n; j > 1; j = i) { i = j / 2; } The signed division can be safely turned into a single shift since j is known to be positive from the loop guard. LLVM currently cannot find out j is positive and compiles the above division into 3 instructions. Any thoughts on where to fix this? Thank you in advance, Haicheng -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160303/4477e92d/attachment.html>
Philip Reames via llvm-dev
2016-Mar-03 22:36 UTC
[llvm-dev] Failure to turn a div by power of 2 into a single shift
SCEV should be able to easily prove that j is positive here. I'm not sure where the right place to use that information would be in this case. Sanjoy, can you comment? Philip On 03/03/2016 02:06 PM, Haicheng Wu wrote:> > Hello, > > I have a simple loop like below > > int I, j; > > for (j = n; j > 1; j = i) { > > i = j / 2; > > } > > The signed division can be safely turned into a single shift since j > is known to be positive from the loop guard. LLVM currently cannot > find out j is positive and compiles the above division into 3 > instructions. Any thoughts on where to fix this? > > Thank you in advance, > > Haicheng >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160303/5e5af97e/attachment.html>
Philip Reames via llvm-dev
2016-Mar-03 22:39 UTC
[llvm-dev] Failure to turn a div by power of 2 into a single shift
I'd missed the fact that j wasn't just being decremented. This isn't as easy as I said. Philip On 03/03/2016 02:36 PM, Philip Reames via llvm-dev wrote:> SCEV should be able to easily prove that j is positive here. I'm not > sure where the right place to use that information would be in this > case. Sanjoy, can you comment? > > Philip > > On 03/03/2016 02:06 PM, Haicheng Wu wrote: >> >> Hello, >> >> I have a simple loop like below >> >> int I, j; >> >> for (j = n; j > 1; j = i) { >> >> i = j / 2; >> >> } >> >> The signed division can be safely turned into a single shift since j >> is known to be positive from the loop guard. LLVM currently cannot >> find out j is positive and compiles the above division into 3 >> instructions. Any thoughts on where to fix this? >> >> Thank you in advance, >> >> Haicheng >> > > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160303/8e011711/attachment.html>