@@ -499,7 +499,7 @@ class LowerToAir {
499499 return true ;
500500 }
501501
502- bool isMergeableValue (Value* v, B3 ::Opcode b3Opcode, bool checkCanBeInternal)
502+ bool isMergeableValue (Value* v, B3 ::Opcode b3Opcode, bool checkCanBeInternal = false )
503503 {
504504 if (v->opcode () != b3Opcode)
505505 return false ;
@@ -516,9 +516,9 @@ class LowerToAir {
516516#if CPU(ARM64)
517517 // Maybe, the ideal approach is to introduce a decorator (Index@EXT) to the Air operand
518518 // to provide an extension opportunity for the specific form under the Air opcode.
519- if (isMergeableValue (index, ZExt32, false ))
519+ if (isMergeableValue (index, ZExt32))
520520 return Arg::index (base, tmp (index->child (0 )), scale, offset, MacroAssembler::Extend::ZExt32);
521- if (isMergeableValue (index, SExt32, false ))
521+ if (isMergeableValue (index, SExt32))
522522 return Arg::index (base, tmp (index->child (0 )), scale, offset, MacroAssembler::Extend::SExt32);
523523#endif
524524 return Arg::index (base, tmp (index), scale, offset);
@@ -2689,19 +2689,17 @@ class LowerToAir {
26892689 if (airOpcode != MultiplyAdd64)
26902690 return Air::Oops;
26912691 // SMADDL: d = SExt32(n) * SExt32(m) + a
2692- if (isMergeableValue (multiplyLeft, SExt32, true ) && isMergeableValue (multiplyRight, SExt32, true ))
2692+ if (isMergeableValue (multiplyLeft, SExt32) && isMergeableValue (multiplyRight, SExt32))
26932693 return MultiplyAddSignExtend32;
26942694 // UMADDL: d = ZExt32(n) * ZExt32(m) + a
2695- if (isMergeableValue (multiplyLeft, ZExt32, true ) && isMergeableValue (multiplyRight, ZExt32, true ))
2695+ if (isMergeableValue (multiplyLeft, ZExt32) && isMergeableValue (multiplyRight, ZExt32))
26962696 return MultiplyAddZeroExtend32;
26972697 return Air::Oops;
26982698 };
26992699
27002700 Air::Opcode newAirOpcode = tryNewAirOpcode ();
27012701 if (isValidForm (newAirOpcode, Arg::Tmp, Arg::Tmp, Arg::Tmp, Arg::Tmp)) {
27022702 append (newAirOpcode, tmp (multiplyLeft->child (0 )), tmp (multiplyRight->child (0 )), tmp (right), tmp (m_value));
2703- commitInternal (multiplyLeft);
2704- commitInternal (multiplyRight);
27052703 commitInternal (left);
27062704 return true ;
27072705 }
@@ -2755,19 +2753,17 @@ class LowerToAir {
27552753 if (airOpcode != MultiplySub64)
27562754 return Air::Oops;
27572755 // SMSUBL: d = a - SExt32(n) * SExt32(m)
2758- if (isMergeableValue (multiplyLeft, SExt32, true ) && isMergeableValue (multiplyRight, SExt32, true ))
2756+ if (isMergeableValue (multiplyLeft, SExt32) && isMergeableValue (multiplyRight, SExt32))
27592757 return MultiplySubSignExtend32;
27602758 // UMSUBL: d = a - ZExt32(n) * ZExt32(m)
2761- if (isMergeableValue (multiplyLeft, ZExt32, true ) && isMergeableValue (multiplyRight, ZExt32, true ))
2759+ if (isMergeableValue (multiplyLeft, ZExt32) && isMergeableValue (multiplyRight, ZExt32))
27622760 return MultiplySubZeroExtend32;
27632761 return Air::Oops;
27642762 };
27652763
27662764 Air::Opcode newAirOpcode = tryNewAirOpcode ();
27672765 if (isValidForm (newAirOpcode, Arg::Tmp, Arg::Tmp, Arg::Tmp, Arg::Tmp)) {
27682766 append (newAirOpcode, tmp (multiplyLeft->child (0 )), tmp (multiplyRight->child (0 )), tmp (left), tmp (m_value));
2769- commitInternal (multiplyLeft);
2770- commitInternal (multiplyRight);
27712767 commitInternal (right);
27722768 return true ;
27732769 }
@@ -2808,19 +2804,17 @@ class LowerToAir {
28082804 if (airOpcode != MultiplyNeg64)
28092805 return Air::Oops;
28102806 // SMNEGL: d = -(SExt32(n) * SExt32(m))
2811- if (isMergeableValue (multiplyLeft, SExt32, true ) && isMergeableValue (multiplyRight, SExt32, true ))
2807+ if (isMergeableValue (multiplyLeft, SExt32) && isMergeableValue (multiplyRight, SExt32))
28122808 return MultiplyNegSignExtend32;
28132809 // UMNEGL: d = -(ZExt32(n) * ZExt32(m))
2814- if (isMergeableValue (multiplyLeft, ZExt32, true ) && isMergeableValue (multiplyRight, ZExt32, true ))
2810+ if (isMergeableValue (multiplyLeft, ZExt32) && isMergeableValue (multiplyRight, ZExt32))
28152811 return MultiplyNegZeroExtend32;
28162812 return Air::Oops;
28172813 };
28182814
28192815 Air::Opcode newAirOpcode = tryNewAirOpcode ();
28202816 if (isValidForm (newAirOpcode, Arg::Tmp, Arg::Tmp, Arg::Tmp)) {
28212817 append (newAirOpcode, tmp (multiplyLeft->child (0 )), tmp (multiplyRight->child (0 )), tmp (m_value));
2822- commitInternal (multiplyLeft);
2823- commitInternal (multiplyRight);
28242818 commitInternal (m_value->child (0 ));
28252819 return true ;
28262820 }
@@ -2842,29 +2836,34 @@ class LowerToAir {
28422836 }
28432837
28442838 case Mul: {
2845- if (m_value->type () == Int64
2846- && isValidForm (MultiplySignExtend32, Arg::Tmp, Arg::Tmp, Arg::Tmp)
2847- && m_value->child (0 )->opcode () == SExt32
2848- && !m_locked.contains (m_value->child (0 ))) {
2849- Value* opLeft = m_value->child (0 );
2850- Value* left = opLeft->child (0 );
2851- Value* opRight = m_value->child (1 );
2852- Value* right = nullptr ;
2853-
2854- if (opRight->opcode () == SExt32 && !m_locked.contains (opRight->child (0 ))) {
2855- right = opRight->child (0 );
2856- } else if (m_value->child (1 )->isRepresentableAs <int32_t >() && !m_locked.contains (m_value->child (1 ))) {
2857- // We just use the 64-bit const int as a 32 bit const int directly
2858- right = opRight;
2859- }
2839+ Value* left = m_value->child (0 );
2840+ Value* right = m_value->child (1 );
28602841
2861- if (right) {
2862- append (MultiplySignExtend32, tmp (left), tmp (right), tmp (m_value));
2863- return ;
2842+ auto tryAppendMultiplyWithExtend = [&] () -> bool {
2843+ auto tryAirOpcode = [&] () -> Air::Opcode {
2844+ if (m_value->type () != Int64)
2845+ return Air::Oops;
2846+ // SMULL: d = SExt32(n) * SExt32(m)
2847+ if (isMergeableValue (left, SExt32) && isMergeableValue (right, SExt32))
2848+ return MultiplySignExtend32;
2849+ // UMULL: d = ZExt32(n) * ZExt32(m)
2850+ if (isMergeableValue (left, ZExt32) && isMergeableValue (right, ZExt32))
2851+ return MultiplyZeroExtend32;
2852+ return Air::Oops;
2853+ };
2854+
2855+ Air::Opcode opcode = tryAirOpcode ();
2856+ if (isValidForm (opcode, Arg::Tmp, Arg::Tmp, Arg::Tmp)) {
2857+ append (opcode, tmp (left->child (0 )), tmp (right->child (0 )), tmp (m_value));
2858+ return true ;
28642859 }
2865- }
2866- appendBinOp<Mul32, Mul64, MulDouble, MulFloat, Commutative>(
2867- m_value->child (0 ), m_value->child (1 ));
2860+ return false ;
2861+ };
2862+
2863+ if (tryAppendMultiplyWithExtend ())
2864+ return ;
2865+
2866+ appendBinOp<Mul32, Mul64, MulDouble, MulFloat, Commutative>(left, right);
28682867 return ;
28692868 }
28702869
@@ -3002,7 +3001,7 @@ class LowerToAir {
30023001 // mask = (1 << lowWidth) - 1
30033002 auto tryAppendEXTR = [&] (Value* left, Value* right) -> bool {
30043003 Air::Opcode opcode = opcodeForType (ExtractRegister32, ExtractRegister64, m_value->type ());
3005- if (!isValidForm (opcode, Arg::Tmp, Arg::Tmp, Arg::Imm, Arg::Tmp))
3004+ if (!isValidForm (opcode, Arg::Tmp, Arg::Tmp, Arg::Imm, Arg::Tmp))
30063005 return false ;
30073006 if (left->opcode () != Shl || left->child (0 )->opcode () != BitAnd || right->opcode () != ZShr)
30083007 return false ;
@@ -3208,7 +3207,7 @@ class LowerToAir {
32083207 XorNotLeftShift32, XorNotLeftShift64,
32093208 XorNotRightShift32, XorNotRightShift64,
32103209 XorNotUnsignedRightShift32, XorNotUnsignedRightShift64);
3211- if (!isValidForm (opcode, Arg::Tmp, Arg::Tmp, Arg::Imm, Arg::Tmp))
3210+ if (!isValidForm (opcode, Arg::Tmp, Arg::Tmp, Arg::Imm, Arg::Tmp))
32123211 return false ;
32133212 Value* mValue = shiftValue->child (0 );
32143213 Value* amountValue = shiftValue->child (1 );
0 commit comments