Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

problematic idiv

oiskuu
Beginner
406 Views
The icc appears to have trouble optimizing with signed 64-bit divisions on x86_64. Sample compiled with icc-11.1.069:
[plain]s_div_rem:
        movq      %rdx, %rcx                                    
        movq      %rdi, %rax                                    
        cqto                                                    
        idivq     %rsi                                          
        movq      %rdi, %rax                                    
        movq      %rdx, (%rcx)                                  
        cqto                                                    
        idivq     %rsi                                          
        ret                                                     

u_div_rem:
        movq      %rdx, %rcx                                    
        movq      %rdi, %rax                                    
        xorl      %edx, %edx                                    
        divq      %rsi                                          
        movq      %rdx, (%rcx)                                  
        ret                                                     
[/plain]
Note that the compiler has failed to eliminate the second idiv. The source code is attached:
0 Kudos
2 Replies
Dale_S_Intel
Employee
406 Views
Sorry for the delay in responding. It looks suspicious to me as well. I'm consulting with our experts on the subject in case there's some subtlety that escapes me, but it could well be a missed optimization opportunity. Thanks for pointing this out, and for the concise test case. I'll let you know what I find.

Thanks!
Dale
0 Kudos
Dale_S_Intel
Employee
406 Views
I've filed CQ153925 on this issue, I'll update here with further info.

Thanks!
Dale
0 Kudos
Reply