This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Handle negative architecture features
ClosedPublic

Authored by dmgreen on Jan 31 2023, 1:49 AM.

Details

Summary

Currently negative architecture features passes to clang like -Xclang -target-feature -Xclang -v9.3a will end up _enabling_ dependant target features (like FEAT_MOPS). This patch fixes that by ensuring we don't enable dependant target features when !Enabled.

Fixes #60375

Diff Detail

Event Timeline

dmgreen created this revision.Jan 31 2023, 1:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 31 2023, 1:49 AM
dmgreen requested review of this revision.Jan 31 2023, 1:49 AM
dmgreen added a reviewer: andrewrk.
pratlucas added inline comments.Jan 31 2023, 1:53 AM
clang/lib/Basic/Targets/AArch64.cpp
687

I believe these changes require a rebase. llvm::AArch64::INVALID was removed by D142539.

tmatheson added a comment.EditedJan 31 2023, 2:42 AM

It looks like this has these odd behaviours:

  • -target-feature +v9.3a -target-feature -v9.2a will remove v9.2a but add all the dependent features of both v9.3a and v9.2a. It also doesn't remove v9.3a which implies v9.2a.
  • -target-feature -v9.2a -target-feature +v9.3a will add the v9.2a back, and also add all the dependent features of both v9.3a and v9.2a.
  • -target-feature +v9.3a -target-feature -v9.3a will remove v9.3a but add all the dependent features of v9.3a.

This seems like a bit of a minefield. Is there even a use case for negative architectural features?

clang/lib/Basic/Targets/AArch64.cpp
687–688

It looks like this has these odd behaviours:

  • -target-feature +v9.3a -target-feature -v9.2a will remove v9.2a but add all the dependent features of both v9.3a and v9.2a. It also doesn't remove v9.3a which implies v9.2a.
  • -target-feature -v9.2a -target-feature +v9.3a will add the v9.2a back, and also add all the dependent features of both v9.3a and v9.2a.
  • -target-feature +v9.3a -target-feature -v9.3a will remove v9.3a but add all the dependent features of v9.3a.

This seems like a bit of a minefield. Is there even a use case for negative architectural features?

Yes - We don't have _any_ dependencies for negative target features at the moment. That is a larger job that will take some time to do properly though.

Between architecture revisions I would say that we can trust whatever is passing the parameters to get it right (not provide contradictory results). Otherwise it is a problem elsewhere. We just need to make sure we don't treat them invalidly. In this case from the linked bug, the features are coming from zig. Clang should always only use positive features. Which is why this bug exists - we didn't expect them to be passed as negative features. We can at least not get the dependent features wrong though.

dmgreen updated this revision to Diff 493656.Jan 31 2023, 10:04 AM

Rebase and address comments.

andrewrk accepted this revision.Jan 31 2023, 12:12 PM

It looks like this has these odd behaviours:

  • -target-feature +v9.3a -target-feature -v9.2a will remove v9.2a but add all the dependent features of both v9.3a and v9.2a. It also doesn't remove v9.3a which implies v9.2a.
  • -target-feature -v9.2a -target-feature +v9.3a will add the v9.2a back, and also add all the dependent features of both v9.3a and v9.2a.
  • -target-feature +v9.3a -target-feature -v9.3a will remove v9.3a but add all the dependent features of v9.3a.

This seems like a bit of a minefield. Is there even a use case for negative architectural features?

Speaking as the one who filed the motivating bug report, all of the above behaviors are fine. The motivating use case is explicitly specifying a full set of enabled/disabled features, leaving nothing changed by LLVM's own dependency resolution. In this use case, LLVM would never see any of these three scenarios as input.

This revision is now accepted and ready to land.Jan 31 2023, 12:12 PM
This revision was landed with ongoing or failed builds.Feb 1 2023, 1:21 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 1 2023, 1:21 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Speaking as the one who filed the motivating bug report, all of the above behaviors are fine. The motivating use case is explicitly specifying a full set of enabled/disabled features, leaving nothing changed by LLVM's own dependency resolution. In this use case, LLVM would never see any of these three scenarios as input.

This is not something that I would recommend that you do, at least until we have a coherent model for what enabling/disabling features via -target-features means with respect to backend features. Currently:

  • Architecture features are treated specially in some cases,
  • it's not clear what negative features mean with respect to dependent features,
  • the order in which you specify the -target-features changes the results,
  • etc.

We don't test any combinations that we don't expect out of the clang driver (these are the first clang tests ever added for negative architecture features). You might have more reliable results if you stick to only using negative features where they are needed to disable features that were implicitly enabled.