This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] fold fpext into Xitofp
ClosedPublic

Authored by spatel on Apr 29 2020, 12:23 PM.

Details

Summary

We can combine a floating-point extension cast with a conversion from integer if we know the earlier cast is exact. For example:
fpext (sitofp (fptosi half F to iN) to float) to double --> sitofp (fptosi half F to iN) to double

This is an optimization suggested in PR36617:
https://bugs.llvm.org/show_bug.cgi?id=36617#c19

I left the mismatched unsigned -> signed pattern out of this patch just in case there's some weird type combo that I'm not seeing. I can add that here if there's no concern.

This gives us another opportunity to test-drive Alive2 with FP ops:
http://volta.cs.utah.edu:8080/z/NfYne7

Diff Detail

Event Timeline

spatel created this revision.Apr 29 2020, 12:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 29 2020, 12:23 PM
spatel added a subscriber: lenary.

Ping.

So the general idea here is centered around an "exact" cast: an sitofp that, for whatever reason, we know never rounds the result. This is sort of the same idea as InstCombiner::FoldItoFPtoI, except that it's using a different method to prove the exact-ness.

Would it make sense to factor out the "IsExactIToFP" predicate into a separate method?

So the general idea here is centered around an "exact" cast: an sitofp that, for whatever reason, we know never rounds the result. This is sort of the same idea as InstCombiner::FoldItoFPtoI, except that it's using a different method to prove the exact-ness.

Would it make sense to factor out the "IsExactIToFP" predicate into a separate method?

Sure, and that makes it possible to split this patch up. In the simplest case, we don't need the leading fptoi instruction (if the integer type is narrow enough, then the itofp may be known exact).

spatel updated this revision to Diff 262942.May 8 2020, 1:23 PM

Patch updated:
Created an exact-ness helper function with rG5cf17034e537, so this patch is now only enabling the simplest case - where the narrow FP type has enough mantissa bits to guarantee that the conversion from integer is exact.

efriedma accepted this revision.May 8 2020, 1:46 PM

LGTM

This revision is now accepted and ready to land.May 8 2020, 1:46 PM
This revision was automatically updated to reflect the committed changes.