[PATCH] D63391: [CodeGen] [SelectionDAG] More efficient code for X % C == 0 (UREM case) (try 2)
Roman Lebedev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 27 13:51:37 PDT 2019
lebedev.ri added a comment.
So the first thought about `multiplicativeInverse()` being broken does **not** appear to be correct
(although that interface is extremely susceptible to misuse),
The miscompiles in test-suite happened for `urem` by `100` (and `10`, did not check for more cases).
This code produces:
define i32 @test_urem_100(i32 %X) nounwind readnone {
; X86-LABEL: test_urem_100:
; X86: # %bb.0:
; X86-NEXT: imull $-1030792151, {{[0-9]+}}(%esp), %ecx # imm = 0xC28F5C29
; X86-NEXT: rorl $2, %ecx
; X86-NEXT: xorl %eax, %eax
; X86-NEXT: cmpl $171798692, %ecx # imm = 0xA3D70A4
; X86-NEXT: setb %al
; X86-NEXT: retl
;
; X64-LABEL: test_urem_100:
; X64: # %bb.0:
; X64-NEXT: imull $-1030792151, %edi, %ecx # imm = 0xC28F5C29
; X64-NEXT: rorl $2, %ecx
; X64-NEXT: xorl %eax, %eax
; X64-NEXT: cmpl $171798692, %ecx # imm = 0xA3D70A4
; X64-NEXT: setb %al
; X64-NEXT: retq
%urem = urem i32 %X, 100
%cmp = icmp eq i32 %urem, 0
%ret = zext i1 %cmp to i32
ret i32 %ret
}
GCC: https://godbolt.org/z/ks6Wm-
imull $-1030792151, %edi, %edi
rorl $2, %edi
cmpl $42949672, %edi
setbe %al
The difference is in the constant we compare with: `171798692` (patch) vs `42949672` (GCC).
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D63391/new/
https://reviews.llvm.org/D63391
More information about the llvm-commits
mailing list