@@ -139,7 +139,7 @@ GenTree* Lowering::LowerNode(GenTree* node)
139139 case GT_AND:
140140 case GT_OR:
141141 case GT_XOR:
142- return LowerBinaryArithmetic (node->AsOp ());
142+ return LowerBinaryArithmeticCommon (node->AsOp ());
143143
144144 case GT_MUL:
145145 case GT_MULHI:
@@ -2708,10 +2708,16 @@ GenTree* Lowering::OptimizeConstCompare(GenTree* cmp)
27082708
27092709 if (op2->IsIntegralConst (0 ) && (op1->gtNext == op2) && (op2->gtNext == cmp) &&
27102710#ifdef TARGET_XARCH
2711- op1->OperIs (GT_AND, GT_OR, GT_XOR, GT_ADD, GT_SUB, GT_NEG))
2711+ (op1->OperIs (GT_AND, GT_OR, GT_XOR, GT_ADD, GT_SUB, GT_NEG)
2712+ #ifdef FEATURE_HW_INTRINSICS
2713+ || (op1->OperIs (GT_HWINTRINSIC) &&
2714+ emitter::DoesWriteZeroFlag (HWIntrinsicInfo::lookupIns (op1->AsHWIntrinsic ())))
2715+ #endif // FEATURE_HW_INTRINSICS
2716+ )
27122717#else // TARGET_ARM64
2713- op1->OperIs (GT_AND, GT_ADD, GT_SUB))
2718+ op1->OperIs (GT_AND, GT_ADD, GT_SUB)
27142719#endif
2720+ )
27152721 {
27162722 op1->gtFlags |= GTF_SET_FLAGS;
27172723 op1->SetUnusedValue ();
@@ -5117,7 +5123,7 @@ GenTree* Lowering::LowerAdd(GenTreeOp* node)
51175123}
51185124
51195125// ------------------------------------------------------------------------
5120- // LowerBinaryArithmetic : lowers the given binary arithmetic node.
5126+ // LowerBinaryArithmeticCommon : lowers the given binary arithmetic node.
51215127//
51225128// Recognizes opportunities for using target-independent "combined" nodes
51235129// (currently AND_NOT on ARMArch). Performs containment checks.
@@ -5128,41 +5134,39 @@ GenTree* Lowering::LowerAdd(GenTreeOp* node)
51285134// Returns:
51295135// The next node to lower.
51305136//
5131- GenTree* Lowering::LowerBinaryArithmetic (GenTreeOp* node )
5137+ GenTree* Lowering::LowerBinaryArithmeticCommon (GenTreeOp* binOp )
51325138{
51335139 // TODO-CQ-XArch: support BMI2 "andn" in codegen and condition
51345140 // this logic on the support for the instruction set on XArch.
51355141 CLANG_FORMAT_COMMENT_ANCHOR;
51365142
51375143#ifdef TARGET_ARMARCH
5138- if (comp->opts .OptimizationEnabled () && node ->OperIs (GT_AND))
5144+ if (comp->opts .OptimizationEnabled () && binOp ->OperIs (GT_AND))
51395145 {
51405146 GenTree* opNode = nullptr ;
51415147 GenTree* notNode = nullptr ;
5142- if (node ->gtGetOp1 ()->OperIs (GT_NOT))
5148+ if (binOp ->gtGetOp1 ()->OperIs (GT_NOT))
51435149 {
5144- notNode = node ->gtGetOp1 ();
5145- opNode = node ->gtGetOp2 ();
5150+ notNode = binOp ->gtGetOp1 ();
5151+ opNode = binOp ->gtGetOp2 ();
51465152 }
5147- else if (node ->gtGetOp2 ()->OperIs (GT_NOT))
5153+ else if (binOp ->gtGetOp2 ()->OperIs (GT_NOT))
51485154 {
5149- notNode = node ->gtGetOp2 ();
5150- opNode = node ->gtGetOp1 ();
5155+ notNode = binOp ->gtGetOp2 ();
5156+ opNode = binOp ->gtGetOp1 ();
51515157 }
51525158
51535159 if (notNode != nullptr )
51545160 {
5155- node ->gtOp1 = opNode;
5156- node ->gtOp2 = notNode->AsUnOp ()->gtGetOp1 ();
5157- node ->ChangeOper (GT_AND_NOT);
5161+ binOp ->gtOp1 = opNode;
5162+ binOp ->gtOp2 = notNode->AsUnOp ()->gtGetOp1 ();
5163+ binOp ->ChangeOper (GT_AND_NOT);
51585164 BlockRange ().Remove (notNode);
51595165 }
51605166 }
5161- #endif // TARGET_ARMARCH
5162-
5163- ContainCheckBinary (node);
5167+ #endif
51645168
5165- return node-> gtNext ;
5169+ return LowerBinaryArithmetic (binOp) ;
51665170}
51675171
51685172// ------------------------------------------------------------------------
0 commit comments