This is an archive of the discontinued LLVM Phabricator instance.

[JumpThreading] Don't limit the type of an operand
ClosedPublic

Authored by aqjune on Jul 30 2020, 7:52 AM.

Details

Summary

Compared to the optimized code with branch conditions never frozen,
limiting the type of freeze's operand causes generation of suboptimal code in
some cases.
I would like to suggest removing the constraint, as this patch does.
If the number of freeze instructions becomes significant, this can be revisited.

Diff Detail

Event Timeline

aqjune created this revision.Jul 30 2020, 7:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 30 2020, 7:52 AM
aqjune requested review of this revision.Jul 30 2020, 7:52 AM
efriedma added inline comments.Jul 30 2020, 12:40 PM
llvm/lib/Transforms/Scalar/JumpThreading.cpp
678

Oh, hmm, I misintepreted this comment, and didn't read the code carefully enough. The "if" is actually a heuristic that suppresses potential optimizations.

Do you have any idea what the actual compile-time impact would be if we just recursed over all casts?

aqjune added inline comments.Jul 31 2020, 1:34 AM
llvm/lib/Transforms/Scalar/JumpThreading.cpp
678

I ran a test, and actually it brought a slight speedup when compiled with -O3 (without LTO):

+-----------------------------------------------+-------+-------+------------+
|                   unit:sec.                   | base  | cast  | speedup(%) |
+-----------------------------------------------+-------+-------+------------+
| CTMark/7zip/7zip-benchmark.test               | 90.18 | 89.83 | 0.39%      |
| CTMark/Bullet/bullet.test                     | 63.11 | 62.92 | 0.31%      |
| CTMark/ClamAV/clamscan.test                   | 27.00 | 26.98 | 0.05%      |
| CTMark/SPASS/SPASS.test                       | 26.27 | 26.14 | 0.52%      |
| CTMark/consumer-typeset/consumer-typeset.test | 19.73 | 19.74 | -0.02%     |
| CTMark/kimwitu++/kc.test                      | 26.60 | 26.51 | 0.37%      |
| CTMark/lencod/lencod.test                     | 34.64 | 34.65 | -0.03%     |
| CTMark/mafft/pairlocalalign.test              | 16.24 | 16.24 | 0.00%      |
| CTMark/sqlite3/sqlite3.test                   | 24.61 | 24.68 | -0.27%     |
| CTMark/tramp3d-v4/tramp3d-v4.test             | 49.35 | 49.24 | 0.22%      |
+-----------------------------------------------+-------+-------+------------+

Would it be a right direction if I remove this condition in a separate patch?

lebedev.ri added inline comments.Jul 31 2020, 3:59 AM
llvm/lib/Transforms/Scalar/JumpThreading.cpp
678

Compile time != run time

aqjune added inline comments.Jul 31 2020, 4:25 AM
llvm/lib/Transforms/Scalar/JumpThreading.cpp
678

The table depicts compile time.

Compilation becomes slightly faster (or almost equivalent, assuming that they are errors) if the conditions are removed, interestingly.

efriedma accepted this revision.Aug 3 2020, 1:48 PM

LGTM

llvm/lib/Transforms/Scalar/JumpThreading.cpp
678

Sure, we can do it in a separate patch.

698

Maybe tweak this comment, if we're going to drop the check for cmpinst.

This revision is now accepted and ready to land.Aug 3 2020, 1:48 PM
aqjune updated this revision to Diff 282811.Aug 4 2020, 12:21 AM

Update the comment

aqjune marked an inline comment as done.Aug 4 2020, 12:21 AM
This revision was landed with ongoing or failed builds.Aug 4 2020, 12:22 AM
This revision was automatically updated to reflect the committed changes.