This is an archive of the discontinued LLVM Phabricator instance.

[flang] Optimize / and % operators for int128.
AbandonedPublic

Authored by sunshaoce on Mar 22 2023, 2:41 AM.

Details

Reviewers
klausler
Summary

I think these modifications should be able to optimize related calculations.
Sorry if I am mistaken.

Diff Detail

Event Timeline

sunshaoce created this revision.Mar 22 2023, 2:41 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMar 22 2023, 2:41 AM
sunshaoce requested review of this revision.Mar 22 2023, 2:41 AM
klausler requested changes to this revision.Mar 22 2023, 12:01 PM

This patch only optimizes cases with upper halves all zero. Signed division has opportunities for optimization when upper halves are all ones, too.

But this code only exists as a backstop for builds with C compilers that don't have native 128-bit ints. Correctness is the only thing that matters. I would be very nervous about changing this code unless its performance became important.

flang/include/flang/Common/uint128.h
23

Please use the CHECK macro from flang/include/Common rather than assert(). Or don't crash at all; the original code returns maximum values for division by zero, which is not unreasonable.

168–169

The original statement ("++quotient;") is more clear.

181

I think this code is wrong for negative *this. Are you sure that (-1) % 2 should be -1? Are you sure that (-3) % (-2) should be -3?

This revision now requires changes to proceed.Mar 22 2023, 12:01 PM

Thank you so much for your comments. I learned a lot from them! I noticed algorithms are ingenious here, so I just wanted to make them faster. I kept only one modification and added a corresponding comment. If you think it's unnecessary, I will close this revision. Thanks again!

sunshaoce abandoned this revision.May 27 2023, 10:37 AM