Open Kmeakin opened 1 month ago
@llvm/issue-subscribers-backend-x86
Author: Karl Meakin (Kmeakin)
@llvm/issue-subscribers-backend-aarch64
Author: Karl Meakin (Kmeakin)
Maybe related to #97879. @vfdff FYI.
I don't think this is related to #97879.
The issue here is that gcc and llvm use slightly different code. gcc uses the sign of the original dividend to do the final shift and sub. LLVM uses the sign of the quotient for the final shift and add.
gcc's algorithm requires the subtract to have a different operand order when the divisor is negative. LLVM uses an add so the operand order doesn't matter since add is commutative, but requires a different magic constant for the multiply for negative divisors.
I think switching to the gcc algorithm doesn't work for vector divide if the vector divisors have different signs since we can't change the operand order of the final subtract on a per element basis.
hi @topperc Now the sdiv is expansed into instruction chain in ISel, which is placed later than LoopVectorizer and SLPVectorizer, so it will not affect vector divide if switching to the gcc algorithm?
GCC is able to generate shorter code for signed division by non-power of 2 constants than clang: https://godbolt.org/z/axeTh4qb8
AArch64, clang:
AArch64, GCC:
x86-64, clang:
x86-64, GCC: