@@ -1628,11 +1628,16 @@ bool VectorCombine::foldPermuteOfBinops(Instruction &I) {
1628
1628
}
1629
1629
1630
1630
// / Try to convert "shuffle (binop), (binop)" into "binop (shuffle), (shuffle)".
1631
+ // / TODO: Handle "shuffle (cmp), (cmp)" into "cmp (shuffle), (shuffle)".
1631
1632
bool VectorCombine::foldShuffleOfBinops (Instruction &I) {
1632
- BinaryOperator *B0, *B1;
1633
1633
ArrayRef<int > OldMask;
1634
- if (!match (&I, m_Shuffle (m_OneUse (m_BinOp (B0)), m_OneUse (m_BinOp (B1)),
1635
- m_Mask (OldMask))))
1634
+ Instruction *LHS, *RHS;
1635
+ if (!match (&I, m_Shuffle (m_OneUse (m_Instruction (LHS)),
1636
+ m_OneUse (m_Instruction (RHS)), m_Mask (OldMask))))
1637
+ return false ;
1638
+
1639
+ BinaryOperator *B0, *B1;
1640
+ if (!match (LHS, m_BinOp (B0)) || !match (RHS, m_BinOp (B1)))
1636
1641
return false ;
1637
1642
1638
1643
// Don't introduce poison into div/rem.
@@ -1645,15 +1650,15 @@ bool VectorCombine::foldShuffleOfBinops(Instruction &I) {
1645
1650
return false ;
1646
1651
1647
1652
auto *ShuffleDstTy = dyn_cast<FixedVectorType>(I.getType ());
1648
- auto *BinOpTy = dyn_cast<FixedVectorType>(B0 ->getType ());
1653
+ auto *BinOpTy = dyn_cast<FixedVectorType>(LHS ->getType ());
1649
1654
if (!ShuffleDstTy || !BinOpTy)
1650
1655
return false ;
1651
1656
1652
1657
unsigned NumSrcElts = BinOpTy->getNumElements ();
1653
1658
1654
1659
// If we have something like "add X, Y" and "add Z, X", swap ops to match.
1655
- Value *X = B0 ->getOperand (0 ), *Y = B0 ->getOperand (1 );
1656
- Value *Z = B1 ->getOperand (0 ), *W = B1 ->getOperand (1 );
1660
+ Value *X = LHS ->getOperand (0 ), *Y = LHS ->getOperand (1 );
1661
+ Value *Z = RHS ->getOperand (0 ), *W = RHS ->getOperand (1 );
1657
1662
if (BinaryOperator::isCommutative (Opcode) && X != Z && Y != W &&
1658
1663
(X == W || Y == Z))
1659
1664
std::swap (X, Y);
@@ -1681,10 +1686,10 @@ bool VectorCombine::foldShuffleOfBinops(Instruction &I) {
1681
1686
1682
1687
// Try to replace a binop with a shuffle if the shuffle is not costly.
1683
1688
InstructionCost OldCost =
1684
- TTI.getArithmeticInstrCost (B0-> getOpcode (), BinOpTy , CostKind) +
1685
- TTI.getArithmeticInstrCost (B1-> getOpcode (), BinOpTy , CostKind) +
1689
+ TTI.getInstructionCost (LHS , CostKind) +
1690
+ TTI.getInstructionCost (RHS , CostKind) +
1686
1691
TTI.getShuffleCost (TargetTransformInfo::SK_PermuteTwoSrc, BinOpTy,
1687
- OldMask, CostKind, 0 , nullptr , {B0, B1 }, &I);
1692
+ OldMask, CostKind, 0 , nullptr , {LHS, RHS }, &I);
1688
1693
1689
1694
InstructionCost NewCost =
1690
1695
TTI.getShuffleCost (SK0, BinOpTy, NewMask0, CostKind, 0 , nullptr , {X, Z}) +
@@ -1703,8 +1708,8 @@ bool VectorCombine::foldShuffleOfBinops(Instruction &I) {
1703
1708
1704
1709
// Intersect flags from the old binops.
1705
1710
if (auto *NewInst = dyn_cast<Instruction>(NewBO)) {
1706
- NewInst->copyIRFlags (B0 );
1707
- NewInst->andIRFlags (B1 );
1711
+ NewInst->copyIRFlags (LHS );
1712
+ NewInst->andIRFlags (RHS );
1708
1713
}
1709
1714
1710
1715
Worklist.pushValue (Shuf0);
0 commit comments