[PATCH] D71312: [InstCombine] Fold X / abs(X) to X < 0 ? -1 : 1
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 10 16:36:57 PST 2019
craig.topper added a comment.
In D71312#1778585 <https://reviews.llvm.org/D71312#1778585>, @xbolva00 wrote:
> Isn't abs(INT_MIN) undefined?
>
> expensive div is removed:
>
> _Z4fooai: # @_Z4fooai
> mov eax, edi
> mov ecx, edi
> neg ecx
> cmovl ecx, edi
> cdq
> idiv ecx
> ret
> _Z5fooari: # @_Z5fooari
> mov eax, edi
> sar eax, 31
> or eax, 1
> ret
>
>
> GCC knows this trick too.
abs(INT_MIN) is only undefined if the sub 0, %x operation that SPF_ABS matched has the nsw flag set on it.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D71312/new/
https://reviews.llvm.org/D71312
More information about the llvm-commits
mailing list