[LLVMdev] A simple case about SDiv

Eli Friedman eli.friedman at gmail.com
Thu Sep 4 10:46:43 PDT 2008


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



More information about the llvm-dev mailing list