src = op2;
}
+ // We can skip emitting 'and reg0, -1` if we know that the upper 32bits of 'reg0' are zero'ed.
+ if (compiler->opts.OptimizationEnabled())
+ {
+ if ((oper == GT_AND) && (targetType == TYP_INT) && !treeNode->gtSetFlags() && op2->IsIntegralConst(-1) &&
+ emit->AreUpper32BitsZero(targetReg))
+ {
+ genProduceReg(treeNode);
+ return;
+ }
+ }
+
// try to use an inc or dec
if (oper == GT_ADD && !varTypeIsFloating(treeNode) && src->isContainedIntOrIImmed() && !treeNode->gtOverflowEx())
{
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Runtime.CompilerServices;
+
+namespace CodeGenTests
+{
+ class IntAnd
+ {
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ static uint Test_And_UInt32_MaxValue(uint i)
+ {
+ // X64: mov
+
+ // X64-NOT: and
+ return i & UInt32.MaxValue;
+ }
+
+ static int Main()
+ {
+ if (Test_And_UInt32_MaxValue(1234) != 1234)
+ return 0;
+
+ return 100;
+ }
+ }
+}
--- /dev/null
+<Project Sdk="Microsoft.NET.Sdk">
+ <PropertyGroup>
+ <OutputType>Exe</OutputType>
+ </PropertyGroup>
+ <PropertyGroup>
+ <DebugType>None</DebugType>
+ <Optimize>True</Optimize>
+ </PropertyGroup>
+ <ItemGroup>
+ <Compile Include="$(MSBuildProjectName).cs">
+ <HasDisasmCheck>true</HasDisasmCheck>
+ </Compile>
+
+ <CLRTestEnvironmentVariable Include="DOTNET_TieredCompilation" Value="0" />
+ <CLRTestEnvironmentVariable Include="DOTNET_JITMinOpts" Value="0" />
+ </ItemGroup>
+</Project>