This is an archive of the discontinued LLVM Phabricator instance.

[LegalizeTypes] Prevent an assertion from PromoteIntRes_BSWAP and PromoteIntRes_BITREVERSE if the shift amount is too large for the VT returned by getShiftAmountTy
ClosedPublic

Authored by craig.topper on Oct 12 2018, 5:29 PM.

Details

Summary

getShiftAmountTy for X86 returns MVT::i8. If a BSWAP or BITREVERSE is created that requires promotion and the difference between the original VT and the promoted VT is more than 255 then we won't able to create the constant.

This patch adds a check to replace the result from getShiftAmountTy to MVT::i32 if the difference won't fit. This should get legalized later when the shift is ultimately expanded since its clearly an illegal type that we're only promoting to make it a power of 2 bit width. Alternatively we could base the decision completely on the largest shift amount the promoted VT could use.

Vectors should be immune here because getShiftAmountTy always returns the incoming VT for vectors. Only the scalar shift amount can be changed by the targets.

Diff Detail

Event Timeline

craig.topper created this revision.Oct 12 2018, 5:29 PM

Correct the calculation for how many bits are needed to store the shift amount. It should be log2(val)+1 not log2_ceil(val)

RKSimon accepted this revision.Oct 13 2018, 4:59 AM

LGTM

This revision is now accepted and ready to land.Oct 13 2018, 4:59 AM
This revision was automatically updated to reflect the committed changes.