This is an archive of the discontinued LLVM Phabricator instance.

Tweak StringRef operators for ever-so-slightly smaller assembly
Needs ReviewPublic

Authored by jordan_rose on Sep 3 2019, 6:17 PM.

Details

Reviewers
jfb
Summary

Although StringRef::compare guarantees to return 0, 1, or -1, testing against 0 saves a single instruction in the implementation of < by replacing a cmp/sete with shr, at least when compiling with Clang. (GCC appears to figure out the idiom regardless.) It's also more obvious that the implementations are correct because the bodies match the operator names.

Diff Detail

Event Timeline

jordan_rose created this revision.Sep 3 2019, 6:17 PM
jordan_rose retitled this revision from Tweak StringRef operators for ever-so-slightly faster assembly to Tweak StringRef operators for ever-so-slightly smaller assembly.Sep 3 2019, 6:17 PM