Handle srem INT_MIN, -1 correctly.

The x86_divmodx traps on integer overflow, but the srem instruction is
not supposed to trap with a -1 divisor.

Generate a legalization expansion for srem that special-cases the -1
divisor to simply return 0.
This commit is contained in:
Jakob Stoklund Olesen
2017-09-29 08:53:49 -07:00
parent 53404a9387
commit 711e5cd644
2 changed files with 58 additions and 6 deletions

View File

@@ -52,12 +52,10 @@ for ty in [i32, i64]:
xhi << insts.sshr_imm(x, imm64(ty.lane_bits() - 1)),
(a, dead) << x86.sdivmodx(x, xhi, y)
))
intel_expand.legalize(
a << insts.srem.bind(ty)(x, y),
Rtl(
xhi << insts.sshr_imm(x, imm64(ty.lane_bits() - 1)),
(dead, a) << x86.sdivmodx(x, xhi, y)
))
# The srem expansion requires custom code because srem INT_MIN, -1 is not
# allowed to trap.
intel_expand.custom_legalize(insts.srem, 'expand_srem')
# Floating point condition codes.
#