This is an archive of the discontinued LLVM Phabricator instance.

[llvm] Fix MCSubtargetInfo::checkFeatures to handle unknown features correctly
Needs ReviewPublic

Authored by RamNalamothu on Feb 9 2023, 6:35 AM.

Diff Detail

Event Timeline

RamNalamothu created this revision.Feb 9 2023, 6:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 9 2023, 6:35 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
RamNalamothu requested review of this revision.Feb 9 2023, 6:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 9 2023, 6:35 AM
dblaikie added inline comments.Feb 10 2023, 2:34 PM
llvm/lib/MC/MCSubtargetInfo.cpp
79–85

avoid else-after-return (per LLVM coding conventions)

And it might even be worth inverting the previous condition (so it's if (!FeatureEntry) { error stuff return false; } non-error stuff here)

But also: we can't/don't usually print errors from arbitrary partts of LLVM - it's not use-LLVM-as-a-library friendly (the library client can't stop these messages from printing, render them in a different way/to a different mechanism (a log, a GUI, etc))

Are there other error handling conventions in use in nearby code you can find some inspiration from?

craig.topper added inline comments.Feb 10 2023, 10:25 PM
llvm/lib/MC/MCSubtargetInfo.cpp
313

Why do we need an Empty set to compare to? Can't we just ask if no bits are set in Set and All? Set.none() && All.none() should work?

Address review comments.

RamNalamothu marked 2 inline comments as done.Feb 12 2023, 11:02 PM

Thanks for the comments @dblaikie @craig.topper.

llvm/lib/MC/MCSubtargetInfo.cpp
79–85

avoid else-after-return (per LLVM coding conventions)

And it might even be worth inverting the previous condition (so it's if (!FeatureEntry) { error stuff return false; } non-error stuff here)

Done, thank you.

But also: we can't/don't usually print errors from arbitrary partts of LLVM - it's not use-LLVM-as-a-library friendly (the library client can't stop these messages from printing, render them in a different way/to a different mechanism (a log, a GUI, etc))

Are there other error handling conventions in use in nearby code you can find some inspiration from?

Since the entire MCSubtargetInfo.cpp is using this same error printing mechanism and I can't find a quick fix, I think that change can be deferred to another patch?

RamNalamothu marked an inline comment as done.Feb 16 2023, 5:28 PM

Ping.

Is this new behavior visible through some existing non-test callers of MCSubtargetInfo::checkFeatures? Could that be tested using a lit-style test to demonstrate that this behavior is desirable/correct at that scope, beyond the narrower unit test?

Is this new behavior visible through some existing non-test callers of MCSubtargetInfo::checkFeatures? Could that be tested using a lit-style test to demonstrate that this behavior is desirable/correct at that scope, beyond the narrower unit test?

Without this change, few lit tests will fail with the updated changeset for D140478. Would that be sufficient to showcase that this change is needed?

Is this new behavior visible through some existing non-test callers of MCSubtargetInfo::checkFeatures? Could that be tested using a lit-style test to demonstrate that this behavior is desirable/correct at that scope, beyond the narrower unit test?

Without this change, few lit tests will fail with the updated changeset for D140478. Would that be sufficient to showcase that this change is needed?

Could you walk me through that in more detail - oh, is that other patch checking for features in generic code on platforms/targets that don't support those features at all? Maybe that's a problem/the thing that should be fixed, and that other code should be moved to some target-specific hook?

Is this new behavior visible through some existing non-test callers of MCSubtargetInfo::checkFeatures? Could that be tested using a lit-style test to demonstrate that this behavior is desirable/correct at that scope, beyond the narrower unit test?

Without this change, few lit tests will fail with the updated changeset for D140478. Would that be sufficient to showcase that this change is needed?

Could you walk me through that in more detail - oh, is that other patch checking for features in generic code on platforms/targets that don't support those features at all? Maybe that's a problem/the thing that should be fixed, and that other code should be moved to some target-specific hook?

That's what it looks like to me. I also think that some virtual methods a target can override would be a better way to solve this.

Is this new behavior visible through some existing non-test callers of MCSubtargetInfo::checkFeatures? Could that be tested using a lit-style test to demonstrate that this behavior is desirable/correct at that scope, beyond the narrower unit test?

Without this change, few lit tests will fail with the updated changeset for D140478. Would that be sufficient to showcase that this change is needed?

Could you walk me through that in more detail - oh, is that other patch checking for features in generic code on platforms/targets that don't support those features at all? Maybe that's a problem/the thing that should be fixed, and that other code should be moved to some target-specific hook?

RamNalamothu added a comment.EditedFeb 24 2023, 12:14 PM

Is this new behavior visible through some existing non-test callers of MCSubtargetInfo::checkFeatures? Could that be tested using a lit-style test to demonstrate that this behavior is desirable/correct at that scope, beyond the narrower unit test?

Without this change, few lit tests will fail with the updated changeset for D140478. Would that be sufficient to showcase that this change is needed?

Could you walk me through that in more detail - oh, is that other patch checking for features in generic code on platforms/targets that don't support those features at all? Maybe that's a problem/the thing that should be fixed, and that other code should be moved to some target-specific hook?

That's what it looks like to me. I also think that some virtual methods a target can override would be a better way to solve this.

Is this new behavior visible through some existing non-test callers of MCSubtargetInfo::checkFeatures? Could that be tested using a lit-style test to demonstrate that this behavior is desirable/correct at that scope, beyond the narrower unit test?

Without this change, few lit tests will fail with the updated changeset for D140478. Would that be sufficient to showcase that this change is needed?

Could you walk me through that in more detail - oh, is that other patch checking for features in generic code on platforms/targets that don't support those features at all? Maybe that's a problem/the thing that should be fixed, and that other code should be moved to some target-specific hook?

Is this new behavior visible through some existing non-test callers of MCSubtargetInfo::checkFeatures? Could that be tested using a lit-style test to demonstrate that this behavior is desirable/correct at that scope, beyond the narrower unit test?

Without this change, few lit tests will fail with the updated changeset for D140478. Would that be sufficient to showcase that this change is needed?

Could you walk me through that in more detail - oh, is that other patch checking for features in generic code on platforms/targets that don't support those features at all? Maybe that's a problem/the thing that should be fixed, and that other code should be moved to some target-specific hook?

That's what it looks like to me. I also think that some virtual methods a target can override would be a better way to solve this.

Is this new behavior visible through some existing non-test callers of MCSubtargetInfo::checkFeatures? Could that be tested using a lit-style test to demonstrate that this behavior is desirable/correct at that scope, beyond the narrower unit test?

Without this change, few lit tests will fail with the updated changeset for D140478. Would that be sufficient to showcase that this change is needed?

Could you walk me through that in more detail - oh, is that other patch checking for features in generic code on platforms/targets that don't support those features at all? Maybe that's a problem/the thing that should be fixed, and that other code should be moved to some target-specific hook?

Thanks for the comments.

Even if we find some other way to address the needs of D140478, I think the incorrect behavior of MCSubtargetInfo::checkFeatures needs to be fixed.

Is having no existing code referring to the use case scenario being fixed a good reason we leave the incorrect behavior in the code base as is?

Thanks for the comments.

Even if we find some other way to address the needs of D140478, I think the incorrect behavior of MCSubtargetInfo::checkFeatures needs to be fixed.

Is having no existing code referring to the use case scenario being fixed a good reason we leave the incorrect behavior in the code base as is?

I'm not sure this is incorrect behavior, though - that this function doesn't handle unknown attributes seems like it could be a valid design. If there's other ways to think about this that demonstrate that the design is not good/incorrect for existing uses, perhaps, maybe that motivates this patch regardless of D140478.

It seems like the only use of checkFeatures is for implementing hwmodes?

llvm/unittests/CodeGen/TargetOptionsTest.cpp
71

It's a gtest-ism that these should be swapped