This is an archive of the discontinued LLVM Phabricator instance.

[PPC] Add RM as call preserved register
Needs ReviewPublic

Authored by Carrot on Aug 30 2022, 6:52 PM.

Details

Reviewers
kbarton
nemanjai
Summary

RM is a call preserved register, but it is missed in current call regmask. This patch adds it.

Diff Detail

Event Timeline

Carrot created this revision.Aug 30 2022, 6:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 30 2022, 6:52 PM
Carrot requested review of this revision.Aug 30 2022, 6:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 30 2022, 6:52 PM

Could any PPC people take a look at this trivial patch?

I don't think we can safely do this.
While the ELFv2 ABI does state that limited access bits can only be modified by functions with specific attributes allowing for such a modification, this isn't implemented in LLVM. Actually, as far as I can tell, it is not implemented in GCC either. So a function that does something like this:

double test() {
  fesetround(2);
  return 88.88;
}

Neither Clang nor GCC add any code to save/restore the RN field of the FPSCR.

While a typical use of the rounding mode is to save it, modify it, do what is necessary, restore it; no guarantees are provided by the compiler so we can't safely assume that the rounding mode is preserved by the callee. Furthermore, I am not aware of any attributes or other machinery in LLVM to mark functions as special wrt. a specific register (as the ABI suggests).

If RM is not preserved by a function call, then in the following example

void foo(double a, double b, double *p) {
  *p++ = a + b;
  bar();
  *p = a + b;
}

The expression a+b can not be CSEd, right?

If RM is not preserved by a function call, then in the following example

void foo(double a, double b, double *p) {
  *p++ = a + b;
  bar();
  *p = a + b;
}

The expression a+b can not be CSEd, right?

The answer is yes and no. It depends on whether the user cares about the rounding mode or not. If user has strict expectation to it, they should use option like -frounding-math. It definitely be CSEd if user uses it in fast FP mode. For the default mode, it still should be CSEd according to C language standard.

It makes no sense to just take care of calling conversion given a lot of middle end optimization don't respect rounding mode. That's why we need to introduce strcit FP.