Hi, I have a simple C case as following: int test(int x, int y) { return -x / -y; } With llvm-gcc -O1, I got: define i32 @test(i32 %x, i32 %y) nounwind { entry: sub i32 0, %x ; <i32>:0 [#uses=1] sub i32 0, %y ; <i32>:1 [#uses=1] sdiv i32 %0, %1 ; <i32>:2 [#uses=1] ret i32 %2 } With llvm-gcc -O2, I got: define i32 @test(i32 %x, i32 %y) nounwind { entry: sdiv i32 %x, %y ; <i32>:0 [#uses=1] ret i32 %0 } I wonder which pass does this transform. I tried several passes, like -instcombine, -simplifycfg, -gcse -globaldce -globalopt -adce , but all failed to do this transform. Anybody know this? Thanks. Sheng. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080904/e0428101/attachment.html>
> I tried several passes, like -instcombine, -simplifycfg, -gcse -globaldce > -globalopt -adce , but all failed to do this transform.Try "opt -std-compile-opts -debug-pass=Arguments" If that does the simplification, then try bisecting the set of passes it ran (printed thanks to -debug-pass) to find out which combination did it. Ciao, Duncan.
Hi Duncan, Thanks for your help. But seems "opt -std-compile-opts" can't do this simplication :( Any ideas? Sheng. 2008/9/4 Duncan Sands <baldrick at free.fr>> > I tried several passes, like -instcombine, -simplifycfg, -gcse -globaldce > > -globalopt -adce , but all failed to do this transform. > > Try "opt -std-compile-opts -debug-pass=Arguments" > If that does the simplification, then try bisecting > the set of passes it ran (printed thanks to -debug-pass) > to find out which combination did it. > > Ciao, > > Duncan. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080905/24bb3f6b/attachment.html>
On Thu, Sep 4, 2008 at 8:31 AM, Zhou Sheng <zhousheng00 at gmail.com> wrote:> Hi, > > I have a simple C case as following: > > int test(int x, int y) { > return -x / -y; > } > > With llvm-gcc -O1, I got: > > define i32 @test(i32 %x, i32 %y) nounwind { > entry: > sub i32 0, %x ; <i32>:0 [#uses=1] > sub i32 0, %y ; <i32>:1 [#uses=1] > sdiv i32 %0, %1 ; <i32>:2 [#uses=1] > ret i32 %2 > } > > With llvm-gcc -O2, I got: > > define i32 @test(i32 %x, i32 %y) nounwind { > entry: > sdiv i32 %x, %y ; <i32>:0 [#uses=1] > ret i32 %0 > } > > I wonder which pass does this transform.No LLVM pass can do this transform; it assumes that integer overflow is undefined, and the conversion to bitcode loses sign information. The optimization level is probably triggering the gcc's folder to be more aggressive. -Eli