This is an archive of the discontinued LLVM Phabricator instance.

[FPEnv] Get rid of extra moves in fpenv calls
ClosedPublic

Authored by sepavloff on May 12 2023, 3:56 AM.

Details

Summary

If intrinsic get_fpenv or set_fpenv is lowered to the form where FP
environment is represented as a region in memory, extra moves can
appear. For example the code:

define void @func_01(ptr %ptr) {
  %env = call i256 @llvm.get.fpenv.i256()
  store i256 %env, ptr %ptr
  ret void
}

produces DAG:

ch = get_fpenv_mem ch, memory_region
val: i256, ch = load ch, memory_region
ch = store ch, ptr, val

In this case the extra moves can be avoided if get_fpenv_mem got
pointer to the memory where the FP environment should be finally placed.

This change implement such optimization for this use case.

Depends on D71742

Diff Detail

Event Timeline

sepavloff created this revision.May 12 2023, 3:56 AM
sepavloff requested review of this revision.May 12 2023, 3:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 12 2023, 3:56 AM
Herald added a subscriber: wdng. · View Herald Transcript
arsenm added inline comments.May 12 2023, 7:29 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
25590–25607

Missing negative tests for most of these conditions?

nikic resigned from this revision.May 13 2023, 9:55 AM
arsenm requested changes to this revision.May 16 2023, 5:46 AM
This revision now requires changes to proceed.May 16 2023, 5:46 AM
sepavloff updated this revision to Diff 523001.May 17 2023, 4:46 AM

Added tests for the cases when folding does not occur

arsenm accepted this revision.May 19 2023, 11:07 AM
This revision is now accepted and ready to land.May 19 2023, 11:07 AM
This revision was landed with ongoing or failed builds.Jun 6 2023, 12:56 AM
This revision was automatically updated to reflect the committed changes.