@@ -1531,16 +1531,16 @@ Instruction *InstCombiner::visitFPTrunc(FPTruncInst &FPT) {
1531
1531
// what we can and cannot do safely varies from operation to operation, and
1532
1532
// is explained below in the various case statements.
1533
1533
Type *Ty = FPT.getType ();
1534
- BinaryOperator *OpI = dyn_cast<BinaryOperator>(FPT.getOperand (0 ));
1535
- if (OpI && OpI ->hasOneUse ()) {
1536
- Type *LHSMinType = getMinimumFPType (OpI ->getOperand (0 ));
1537
- Type *RHSMinType = getMinimumFPType (OpI ->getOperand (1 ));
1538
- unsigned OpWidth = OpI ->getType ()->getFPMantissaWidth ();
1534
+ auto *BO = dyn_cast<BinaryOperator>(FPT.getOperand (0 ));
1535
+ if (BO && BO ->hasOneUse ()) {
1536
+ Type *LHSMinType = getMinimumFPType (BO ->getOperand (0 ));
1537
+ Type *RHSMinType = getMinimumFPType (BO ->getOperand (1 ));
1538
+ unsigned OpWidth = BO ->getType ()->getFPMantissaWidth ();
1539
1539
unsigned LHSWidth = LHSMinType->getFPMantissaWidth ();
1540
1540
unsigned RHSWidth = RHSMinType->getFPMantissaWidth ();
1541
1541
unsigned SrcWidth = std::max (LHSWidth, RHSWidth);
1542
1542
unsigned DstWidth = Ty->getFPMantissaWidth ();
1543
- switch (OpI ->getOpcode ()) {
1543
+ switch (BO ->getOpcode ()) {
1544
1544
default : break ;
1545
1545
case Instruction::FAdd:
1546
1546
case Instruction::FSub:
@@ -1563,10 +1563,10 @@ Instruction *InstCombiner::visitFPTrunc(FPTruncInst &FPT) {
1563
1563
// could be tightened for those cases, but they are rare (the main
1564
1564
// case of interest here is (float)((double)float + float)).
1565
1565
if (OpWidth >= 2 *DstWidth+1 && DstWidth >= SrcWidth) {
1566
- Value *LHS = Builder.CreateFPTrunc (OpI ->getOperand (0 ), Ty);
1567
- Value *RHS = Builder.CreateFPTrunc (OpI ->getOperand (1 ), Ty);
1568
- Instruction *RI = BinaryOperator::Create (OpI ->getOpcode (), LHS, RHS);
1569
- RI->copyFastMathFlags (OpI );
1566
+ Value *LHS = Builder.CreateFPTrunc (BO ->getOperand (0 ), Ty);
1567
+ Value *RHS = Builder.CreateFPTrunc (BO ->getOperand (1 ), Ty);
1568
+ Instruction *RI = BinaryOperator::Create (BO ->getOpcode (), LHS, RHS);
1569
+ RI->copyFastMathFlags (BO );
1570
1570
return RI;
1571
1571
}
1572
1572
break ;
@@ -1577,9 +1577,9 @@ Instruction *InstCombiner::visitFPTrunc(FPTruncInst &FPT) {
1577
1577
// rounding can possibly occur; we can safely perform the operation
1578
1578
// in the destination format if it can represent both sources.
1579
1579
if (OpWidth >= LHSWidth + RHSWidth && DstWidth >= SrcWidth) {
1580
- Value *LHS = Builder.CreateFPTrunc (OpI ->getOperand (0 ), Ty);
1581
- Value *RHS = Builder.CreateFPTrunc (OpI ->getOperand (1 ), Ty);
1582
- return BinaryOperator::CreateFMulFMF (LHS, RHS, OpI );
1580
+ Value *LHS = Builder.CreateFPTrunc (BO ->getOperand (0 ), Ty);
1581
+ Value *RHS = Builder.CreateFPTrunc (BO ->getOperand (1 ), Ty);
1582
+ return BinaryOperator::CreateFMulFMF (LHS, RHS, BO );
1583
1583
}
1584
1584
break ;
1585
1585
case Instruction::FDiv:
@@ -1590,9 +1590,9 @@ Instruction *InstCombiner::visitFPTrunc(FPTruncInst &FPT) {
1590
1590
// condition used here is a good conservative first pass.
1591
1591
// TODO: Tighten bound via rigorous analysis of the unbalanced case.
1592
1592
if (OpWidth >= 2 *DstWidth && DstWidth >= SrcWidth) {
1593
- Value *LHS = Builder.CreateFPTrunc (OpI ->getOperand (0 ), Ty);
1594
- Value *RHS = Builder.CreateFPTrunc (OpI ->getOperand (1 ), Ty);
1595
- return BinaryOperator::CreateFDivFMF (LHS, RHS, OpI );
1593
+ Value *LHS = Builder.CreateFPTrunc (BO ->getOperand (0 ), Ty);
1594
+ Value *RHS = Builder.CreateFPTrunc (BO ->getOperand (1 ), Ty);
1595
+ return BinaryOperator::CreateFDivFMF (LHS, RHS, BO );
1596
1596
}
1597
1597
break ;
1598
1598
case Instruction::FRem: {
@@ -1604,14 +1604,14 @@ Instruction *InstCombiner::visitFPTrunc(FPTruncInst &FPT) {
1604
1604
break ;
1605
1605
Value *LHS, *RHS;
1606
1606
if (LHSWidth == SrcWidth) {
1607
- LHS = Builder.CreateFPTrunc (OpI ->getOperand (0 ), LHSMinType);
1608
- RHS = Builder.CreateFPTrunc (OpI ->getOperand (1 ), LHSMinType);
1607
+ LHS = Builder.CreateFPTrunc (BO ->getOperand (0 ), LHSMinType);
1608
+ RHS = Builder.CreateFPTrunc (BO ->getOperand (1 ), LHSMinType);
1609
1609
} else {
1610
- LHS = Builder.CreateFPTrunc (OpI ->getOperand (0 ), RHSMinType);
1611
- RHS = Builder.CreateFPTrunc (OpI ->getOperand (1 ), RHSMinType);
1610
+ LHS = Builder.CreateFPTrunc (BO ->getOperand (0 ), RHSMinType);
1611
+ RHS = Builder.CreateFPTrunc (BO ->getOperand (1 ), RHSMinType);
1612
1612
}
1613
1613
1614
- Value *ExactResult = Builder.CreateFRemFMF (LHS, RHS, OpI );
1614
+ Value *ExactResult = Builder.CreateFRemFMF (LHS, RHS, BO );
1615
1615
return CastInst::CreateFPCast (ExactResult, Ty);
1616
1616
}
1617
1617
}
0 commit comments