File tree Expand file tree Collapse file tree 2 files changed +46
-3
lines changed Expand file tree Collapse file tree 2 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -32399,10 +32399,10 @@ GenTree* Compiler::gtFoldExprHWIntrinsic(GenTreeHWIntrinsic* tree)
32399
32399
GenTreeHWIntrinsic* cvtOp1 = op1->AsHWIntrinsic();
32400
32400
GenTreeHWIntrinsic* cvtOp2 = (effectiveOper == GT_NOT) ? cvtOp1 : op2->AsHWIntrinsic();
32401
32401
32402
- unsigned simdBaseTypeSize = genTypeSize(simdBaseType);
32402
+ var_types op1SimdBaseType = cvtOp1->GetSimdBaseType();
32403
+ var_types op2SimdBaseType = cvtOp2->GetSimdBaseType();
32403
32404
32404
- if ((genTypeSize(cvtOp1->GetSimdBaseType()) == simdBaseTypeSize) &&
32405
- (genTypeSize(cvtOp2->GetSimdBaseType()) == simdBaseTypeSize))
32405
+ if (genTypeSize(op1SimdBaseType) == genTypeSize(op2SimdBaseType))
32406
32406
{
32407
32407
// We need both operands to be the same kind of mask; otherwise
32408
32408
// the bitwise operation can differ in how it performs
@@ -32455,6 +32455,12 @@ GenTree* Compiler::gtFoldExprHWIntrinsic(GenTreeHWIntrinsic* tree)
32455
32455
tree->gtFlags &= ~GTF_REVERSE_OPS;
32456
32456
}
32457
32457
32458
+ // The bitwise operation is likely normalized to int or uint, while
32459
+ // the underlying convert ops may be a small type. We need to preserve
32460
+ // such a small type since that indicates how many elements are in the mask.
32461
+ simdBaseJitType = cvtOp1->GetSimdBaseJitType();
32462
+ tree->SetSimdBaseJitType(simdBaseJitType);
32463
+
32458
32464
tree->gtType = TYP_MASK;
32459
32465
DEBUG_DESTROY_NODE(op1);
32460
32466
Original file line number Diff line number Diff line change @@ -11279,6 +11279,43 @@ GenTree* Compiler::fgMorphHWIntrinsic(GenTreeHWIntrinsic* tree)
11279
11279
// Perform the required oper-specific postorder morphing
11280
11280
//
11281
11281
11282
+ // If the folded tree is a vector to mask conversion, or vice versa,
11283
+ // then we want to morph the inner operand as we may have folded something
11284
+ // like xor(masktovector(op1), AllBitsSet) into masktovector(not(op1)), which
11285
+ // can unlock further optimizations over op1, like the ability to invert
11286
+ // not(cmple(op1, op2)) into cmpgt(op1, op2)
11287
+
11288
+ int opIndex = 0;
11289
+
11290
+ if (tree->OperIsConvertVectorToMask() || tree->OperIsConvertMaskToVector())
11291
+ {
11292
+ opIndex = 1;
11293
+ }
11294
+
11295
+ #if defined(TARGET_ARM64)
11296
+ if (tree->OperIsConvertVectorToMask())
11297
+ {
11298
+ opIndex = 2;
11299
+ }
11300
+ #endif // TARGET_ARM64
11301
+
11302
+ if (opIndex != 0)
11303
+ {
11304
+ GenTree* innerOp = tree->Op(opIndex);
11305
+
11306
+ if (innerOp->OperIsHWIntrinsic())
11307
+ {
11308
+ innerOp = fgMorphHWIntrinsicRequired(innerOp->AsHWIntrinsic());
11309
+
11310
+ if (innerOp->OperIsHWIntrinsic())
11311
+ {
11312
+ innerOp = fgMorphHWIntrinsicOptional(innerOp->AsHWIntrinsic());
11313
+ }
11314
+
11315
+ tree->Op(opIndex) = innerOp;
11316
+ }
11317
+ }
11318
+
11282
11319
morphedTree = fgMorphHWIntrinsicRequired(tree);
11283
11320
11284
11321
if (morphedTree->OperIsHWIntrinsic())
You can’t perform that action at this time.
0 commit comments