there aren't a lot of good ways to express a portable overflow check for a multiply in conformant C. here's one way that people do it:
a > (UINT_MAX /u b)
this patch teaches instcombine to turn this back into a umul.with.overflow
Differential D20327
[InstCombine] transform multiplication overflow check written as a > (UINT_MAX /u b) to umul.with.overflow regehr on May 17 2016, 6:16 AM. Authored by
Details
Diff Detail Event TimelineComment Actions @sanjoy, you dealt with this sort of canonicalization before. What are your thoughts? Would we want this is InstCombine or CGP? umul_with_overflow may be more canonical because it can be speculated...
Comment Actions The conclusions / guidelines decided from the earlier work were
@regehr is there some specific reason it helps to canonicalize like this? Comment Actions Hi guys, I don't know the best place for this-- just wanted to implement it since Rich Felker, author of Musl libc, was complaining that the transformation is missing. If this isn't the right place I'm happy to close this out. |
This might not be a canonical transform if the division has multiple users.