Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't always do optimistic HW intrinsic expansion #89282

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/coreclr/tools/Common/InstructionSetHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace System.CommandLine
internal static partial class Helpers
{
public static InstructionSetSupport ConfigureInstructionSetSupport(string instructionSet, int maxVectorTBitWidth, bool isVectorTOptimistic, TargetArchitecture targetArchitecture, TargetOS targetOS,
string mustNotBeMessage, string invalidImplicationMessage, Logger logger)
string mustNotBeMessage, string invalidImplicationMessage, Logger logger, bool optimizingForSize = false)
{
InstructionSetSupportBuilder instructionSetSupportBuilder = new(targetArchitecture);

Expand All @@ -38,8 +38,16 @@ public static InstructionSetSupport ConfigureInstructionSetSupport(string instru
}
}

// Whether to allow optimistically expanding the instruction sets beyond what was specified.
// We seed this from optimizingForSize - if we're size-optimizing, we don't want to unnecessarily
// compile both branches of IsSupported checks.
bool allowOptimistic = !optimizingForSize;

if (instructionSet == "native")
{
// We're compiling for a specific chip
allowOptimistic = false;

if (GetTargetArchitecture(null) != targetArchitecture)
{
throw new CommandLineException("Instruction set 'native' not supported when cross-compiling to a different architecture.");
Expand Down Expand Up @@ -123,7 +131,7 @@ public static InstructionSetSupport ConfigureInstructionSetSupport(string instru
InstructionSetSupportBuilder optimisticInstructionSetSupportBuilder = new InstructionSetSupportBuilder(instructionSetSupportBuilder);

// Optimistically assume some instruction sets are present.
if (targetArchitecture == TargetArchitecture.X86 || targetArchitecture == TargetArchitecture.X64)
if (allowOptimistic && (targetArchitecture == TargetArchitecture.X86 || targetArchitecture == TargetArchitecture.X64))
{
// We set these hardware features as opportunistically enabled as most of hardware in the wild supports them.
// Note that we do not indicate support for AVX, or any other instruction set which uses the VEX encodings as
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/tools/aot/ILCompiler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public int Run()
TargetArchitecture targetArchitecture = Get(_command.TargetArchitecture);
TargetOS targetOS = Get(_command.TargetOS);
InstructionSetSupport instructionSetSupport = Helpers.ConfigureInstructionSetSupport(Get(_command.InstructionSet), Get(_command.MaxVectorTBitWidth), isVectorTOptimistic, targetArchitecture, targetOS,
"Unrecognized instruction set {0}", "Unsupported combination of instruction sets: {0}/{1}", logger);
"Unrecognized instruction set {0}", "Unsupported combination of instruction sets: {0}/{1}", logger,
optimizingForSize: _command.OptimizationMode == OptimizationMode.PreferSize);

string systemModuleName = Get(_command.SystemModuleName);
string reflectionData = Get(_command.ReflectionData);
Expand Down