This is an archive of the discontinued LLVM Phabricator instance.

add the -mrecip driver flag and process its options
ClosedPublic

Authored by spatel on Apr 11 2015, 3:24 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

spatel updated this revision to Diff 23644.Apr 11 2015, 3:24 PM
spatel retitled this revision from to [x86] add the -mrecip driver flag and process its options.
spatel updated this object.
spatel edited the test plan for this revision. (Show Details)
spatel added reviewers: hfinkel, andreadb, alexr.
spatel added a subscriber: Unknown Object (MLST).
hfinkel requested changes to this revision.Apr 11 2015, 4:58 PM
hfinkel edited edge metadata.
hfinkel added inline comments.
lib/Driver/Tools.cpp
1581 ↗(On Diff #23644)

As I commented in D8982, I'd like to see options for these added to TargetOptions.h, and then we can handle these in a uniform way across targets. Also, these should default to being on when -ffast-math is enabled, but we can override the defaults with these options.

This revision now requires changes to proceed.Apr 11 2015, 4:58 PM
spatel updated this revision to Diff 23816.Apr 15 2015, 5:58 PM
spatel retitled this revision from [x86] add the -mrecip driver flag and process its options to add the -mrecip driver flag and process its options.
spatel edited edge metadata.

Patch updated to treat -mrecip as a target-independent flag. Clang just does some simple transforms and error-checking on the input strings and passes them through to the backend. The backend is responsible for further processing and target-specific default settings.

Forgot to mention: as noted in the LLVM patch, this is a superset of gcc's PowerPC and x86 options and then some. We can handle float/double, scalar/vector, and div/sqrt independently and also specify the number of refinement steps per operation type.

hfinkel added inline comments.May 14 2015, 1:02 PM
lib/Driver/Tools.cpp
1633 ↗(On Diff #23816)

You should either accept duplicates, or provide a specific error on the duplicated keys. Don't just complain about the number, that's not informative.

1662 ↗(On Diff #23816)

Why can these be negative?

spatel added inline comments.May 15 2015, 7:58 AM
lib/Driver/Tools.cpp
1662 ↗(On Diff #23816)

'IsNegative' may just be a poor name choice. I followed the lead of similar code in this file and copied that name.

The '-' prefix on an option means "disable this type of reciprocal".

Please let me know if I've misunderstood your question.

hfinkel added inline comments.May 15 2015, 8:00 AM
lib/Driver/Tools.cpp
1662 ↗(On Diff #23816)

You did not misunderstand, but I agree, the naming is poor. Let's not replicate it. How about naming it IsDisabled?

spatel added inline comments.May 15 2015, 8:02 AM
lib/Driver/Tools.cpp
1662 ↗(On Diff #23816)

Yep - that's better. Will fix.

spatel updated this revision to Diff 25878.May 15 2015, 10:50 AM
spatel edited edge metadata.

Patch updated:

  1. Changed to error out on duplicate argument settings to the -mrecip option; eg: -mrecip=divf,divf
  2. Improved variable names
  3. Changed refinement step token to ':' (this just looks better than '.' IMO)
  4. Fixed logic bug when parsing optional refinement step arg; was allowing correct prefix with bogus suffix ('divffoo') to get through

I apologize for not looking at this earlier, but the syntax you're accepting is subtly different from GCC's syntax, and I think that we should try to accept a superset of gcc's syntax (not something subtly different).

GCC, to combine the x86 and PPC options, accepts the keys all, default, div (for both divf and divd), divf, divd, rsqrt (for both rsqrtf and rsqrtd), rsqrtf, rsqrtd, and then these same things with the 'vec-' prefix. '!' is used as the prefix to indicate disabling (not '-' as you have here).

I'm fine with the :<n> syntax extension, but I'd rather use GCC's syntax here as a base for compatibility.

GCC, to combine the x86 and PPC options, accepts the keys all, default, div (for both divf and divd), divf, divd, rsqrt (for both rsqrtf and rsqrtd), rsqrtf, rsqrtd, and then these same things with the 'vec-' prefix. '!' is used as the prefix to indicate disabling (not '-' as you have here).

I'm fine with the :<n> syntax extension, but I'd rather use GCC's syntax here as a base for compatibility.

Ok - I missed the f/d shortcut. I wasn't sure if compatibility with GCC (the '!') trumped the existing enable/disable (+/-) syntax that we use for target features. Let me know if we should keep the +/- for the llc command-line or switch that to ! as well.

GCC, to combine the x86 and PPC options, accepts the keys all, default, div (for both divf and divd), divf, divd, rsqrt (for both rsqrtf and rsqrtd), rsqrtf, rsqrtd, and then these same things with the 'vec-' prefix. '!' is used as the prefix to indicate disabling (not '-' as you have here).

I'm fine with the :<n> syntax extension, but I'd rather use GCC's syntax here as a base for compatibility.

Ok - I missed the f/d shortcut. I wasn't sure if compatibility with GCC (the '!') trumped the existing enable/disable (+/-) syntax that we use for target features. Let me know if we should keep the +/- for the llc command-line or switch that to ! as well.

I'd rather you keep the llc syntax the same.

GCC, to combine the x86 and PPC options, accepts the keys all, default, div (for both divf and divd), divf, divd, rsqrt (for both rsqrtf and rsqrtd), rsqrtf, rsqrtd, and then these same things with the 'vec-' prefix. '!' is used as the prefix to indicate disabling (not '-' as you have here).

I'm fine with the :<n> syntax extension, but I'd rather use GCC's syntax here as a base for compatibility.

Ok - I missed the f/d shortcut. I wasn't sure if compatibility with GCC (the '!') trumped the existing enable/disable (+/-) syntax that we use for target features. Let me know if we should keep the +/- for the llc command-line or switch that to ! as well.

I'd rather you keep the llc syntax the same.

I realize that's ambiguous. I'd rather the llc syntax match the Clang syntax.

'!' is used as the prefix to indicate disabling (not '-' as you have here).

Hmm...how does this ever work as advertised?

$ gcc -O2 -ffast-math -mrecip=!sqrt recip.c 
bash: !sqrt: event not found
  • Original Message -----

From: "Sanjay Patel" <spatel@rotateright.com>
To: spatel@rotateright.com, "Andrea DiBiagio" <Andrea_DiBiagio@sn.scee.net>, alexr@leftfield.org, hfinkel@anl.gov
Cc: cfe-commits@cs.uiuc.edu
Sent: Sunday, May 17, 2015 10:46:22 AM
Subject: Re: [PATCH] add the -mrecip driver flag and process its options

In http://reviews.llvm.org/D8989#173900, @hfinkel wrote:

'!' is used as the prefix to indicate disabling (not '-' as you
have here).

Hmm...how does this ever work as advertised?

$ gcc -O2 -ffast-math -mrecip=!sqrt recip.c
bash: !sqrt: event not found

You need quotes.

-Hal

http://reviews.llvm.org/D8989

EMAIL PREFERENCES

http://reviews.llvm.org/settings/panel/emailpreferences/

'!' is used as the prefix to indicate disabling (not '-' as you
have here).

Hmm...how does this ever work as advertised?

$ gcc -O2 -ffast-math -mrecip=!sqrt recip.c
bash: !sqrt: event not found

You need quotes.

Right; I'm just questioning whether it's worth following gcc on this interface that requires quotes/escapes in common shells when we have an existing syntax that works without it.

'!' is used as the prefix to indicate disabling (not '-' as you
have here).

Hmm...how does this ever work as advertised?

$ gcc -O2 -ffast-math -mrecip=!sqrt recip.c
bash: !sqrt: event not found

You need quotes.

Right; I'm just questioning whether it's worth following gcc on this interface that requires quotes/escapes in common shells when we have an existing syntax that works without it.

Yes, it is worth it. There is no reason to force users to remember which compiler uses which minor syntactic differences. Users end up quoting lots of stuff, and turning off these reciprocal estimates in modes where they are otherwise on is likely to be rare, so I'm not particularly bothered by the quoting.

That having been said, I'm not enamored with GCC's syntax, plus, as you know, what GCC accepts is actually different depending on the target (x86 vs. PPC, etc.) I think we should either accept this logicak superset with the same syntax as GCC, or just break with GCC completely and use a different option name (maybe -mrecip-est=..., or something like that, which I think is clearer anyway).

Yes, it is worth it. There is no reason to force users to remember which compiler uses which minor syntactic differences. Users end up quoting lots of stuff, and turning off these reciprocal estimates in modes where they are otherwise on is likely to be rare, so I'm not particularly bothered by the quoting.

That having been said, I'm not enamored with GCC's syntax, plus, as you know, what GCC accepts is actually different depending on the target (x86 vs. PPC, etc.) I think we should either accept this logicak superset with the same syntax as GCC, or just break with GCC completely and use a different option name (maybe -mrecip-est=..., or something like that, which I think is clearer anyway).

Thanks for the explanation, Hal. I'm not sure which is the greater inconvenience for users (incompatiblity or hostile syntax). Given that we've come this far without supporting -mrecip at all, I agree that it's not worth worrying about too much.

I've gone ahead with the '!' syntax here and in D8982. If we can find a clear preference from users, I assume we can change the interface before this makes it into a clang release. I've tried to make the code changes needed for that as obvious and minimal as possible.

spatel updated this revision to Diff 26017.May 18 2015, 2:31 PM

Patch updated:

  1. Use '!' for disabling; match existing gcc syntax
  2. Added ability to specify recip type without precision (float / double)
hfinkel added inline comments.May 20 2015, 1:47 PM
lib/Driver/Tools.cpp
1623 ↗(On Diff #26017)

Don't name this like a macro.

1646 ↗(On Diff #26017)

Don't name these like macros.

spatel updated this revision to Diff 26187.May 20 2015, 3:41 PM

Patch updated:
Fixed variable names to not look like macros.

hfinkel accepted this revision.May 22 2015, 12:21 PM
hfinkel edited edge metadata.

LGTM (pending the LLVM change obviously).

lib/Driver/Tools.cpp
1635 ↗(On Diff #26187)

Please add a comment here explaining that this is reasonable because for currently-supported operations on currently-supported architectures, reasonable value here are 0 through 5 or 6 (and 9 is certainly overkill). We can extend this to support larger numbers as necessary in the future.

This revision is now accepted and ready to land.May 22 2015, 12:21 PM
spatel updated this revision to Diff 26342.May 22 2015, 1:43 PM
spatel edited edge metadata.

Patch updated:
Added comment to explain why a single digit is all we need to specify the number of refinement steps for now.

This revision was automatically updated to reflect the committed changes.