This is an archive of the discontinued LLVM Phabricator instance.

[CGBuiltin] Handle unsigned mul overflow properly (PR35750)
ClosedPublic

Authored by vsk on Jan 3 2018, 2:33 PM.

Details

Summary

r320902 fixed the IRGen for some types of checked multiplications. It
did not handle unsigned overflow correctly in the case where the signed
operand is negative (PR35750).

Eli pointed out that on overflow, the result must be equal to the unique
value that is equivalent to the mathematically-correct result modulo two
raised to the k power, where k is the number of bits in the result type.

This patch fixes the specialized IRGen from r320902 accordingly.

Testing: Apart from check-clang, I modified the test harness from
r320902 to validate the results of all multiplications -- not just the
ones which don't overflow:

https://gist.github.com/vedantk/3eb9c88f82e5c32f2e590555b4af5081

llvm.org/PR35750, rdar://34963321

Diff Detail

Repository
rL LLVM

Event Timeline

vsk created this revision.Jan 3 2018, 2:33 PM
efriedma accepted this revision.Jan 3 2018, 2:36 PM

LGTM

This revision is now accepted and ready to land.Jan 3 2018, 2:36 PM
This revision was automatically updated to reflect the committed changes.