@@ -2637,18 +2637,18 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator &I) {
2637
2637
// This is a generous interpretation for noimplicitfloat, this is not a true
2638
2638
// floating-point operation.
2639
2639
//
2640
- // Assumes any floating point type has the sign bit in the high bit.
2641
2640
// TODO: Unify with APInt matcher. This version allows undef unlike m_APInt
2642
2641
Value *CastOp;
2643
2642
if (match (Op0, m_ElementWiseBitCast (m_Value (CastOp))) &&
2644
- CastOp->getType ()->isFPOrFPVectorTy () &&
2645
- APFloat::hasSignBitInMSB (
2646
- CastOp->getType ()->getScalarType ()->getFltSemantics ()) &&
2647
2643
match (Op1, m_MaxSignedValue ()) &&
2648
2644
!Builder.GetInsertBlock ()->getParent ()->hasFnAttribute (
2649
2645
Attribute::NoImplicitFloat)) {
2650
- Value *FAbs = Builder.CreateUnaryIntrinsic (Intrinsic::fabs, CastOp);
2651
- return new BitCastInst (FAbs, I.getType ());
2646
+ Type *EltTy = CastOp->getType ()->getScalarType ();
2647
+ if (EltTy->isFloatingPointTy () &&
2648
+ APFloat::hasSignBitInMSB (EltTy->getFltSemantics ())) {
2649
+ Value *FAbs = Builder.CreateUnaryIntrinsic (Intrinsic::fabs, CastOp);
2650
+ return new BitCastInst (FAbs, I.getType ());
2651
+ }
2652
2652
}
2653
2653
2654
2654
// and(shl(zext(X), Y), SignMask) -> and(sext(X), SignMask)
@@ -4047,21 +4047,20 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
4047
4047
// the number of instructions. This is still probably a better canonical form
4048
4048
// as it enables FP value tracking.
4049
4049
//
4050
- // Assumes any floating point type has the sign bit in the high bit.
4051
- //
4052
4050
// This is generous interpretation of noimplicitfloat, this is not a true
4053
4051
// floating-point operation.
4054
4052
Value *CastOp;
4055
4053
if (match (Op0, m_ElementWiseBitCast (m_Value (CastOp))) &&
4056
- CastOp->getType ()->isFPOrFPVectorTy () &&
4057
- APFloat::hasSignBitInMSB (
4058
- CastOp->getType ()->getScalarType ()->getFltSemantics ()) &&
4059
4054
match (Op1, m_SignMask ()) &&
4060
4055
!Builder.GetInsertBlock ()->getParent ()->hasFnAttribute (
4061
4056
Attribute::NoImplicitFloat)) {
4062
- Value *FAbs = Builder.CreateUnaryIntrinsic (Intrinsic::fabs, CastOp);
4063
- Value *FNegFAbs = Builder.CreateFNeg (FAbs);
4064
- return new BitCastInst (FNegFAbs, I.getType ());
4057
+ Type *EltTy = CastOp->getType ()->getScalarType ();
4058
+ if (EltTy->isFloatingPointTy () &&
4059
+ APFloat::hasSignBitInMSB (EltTy->getFltSemantics ())) {
4060
+ Value *FAbs = Builder.CreateUnaryIntrinsic (Intrinsic::fabs, CastOp);
4061
+ Value *FNegFAbs = Builder.CreateFNeg (FAbs);
4062
+ return new BitCastInst (FNegFAbs, I.getType ());
4063
+ }
4065
4064
}
4066
4065
4067
4066
// (X & C1) | C2 -> X & (C1 | C2) iff (X & C2) == C2
@@ -4851,18 +4850,18 @@ Instruction *InstCombinerImpl::visitXor(BinaryOperator &I) {
4851
4850
// This is generous interpretation of noimplicitfloat, this is not a true
4852
4851
// floating-point operation.
4853
4852
//
4854
- // Assumes any floating point type has the sign bit in the high bit.
4855
4853
// TODO: Unify with APInt matcher. This version allows undef unlike m_APInt
4856
4854
Value *CastOp;
4857
4855
if (match (Op0, m_ElementWiseBitCast (m_Value (CastOp))) &&
4858
- CastOp->getType ()->isFPOrFPVectorTy () &&
4859
- APFloat::hasSignBitInMSB (
4860
- CastOp->getType ()->getScalarType ()->getFltSemantics ()) &&
4861
4856
match (Op1, m_SignMask ()) &&
4862
4857
!Builder.GetInsertBlock ()->getParent ()->hasFnAttribute (
4863
4858
Attribute::NoImplicitFloat)) {
4864
- Value *FNeg = Builder.CreateFNeg (CastOp);
4865
- return new BitCastInst (FNeg, I.getType ());
4859
+ Type *EltTy = CastOp->getType ()->getScalarType ();
4860
+ if (EltTy->isFloatingPointTy () &&
4861
+ APFloat::hasSignBitInMSB (EltTy->getFltSemantics ())) {
4862
+ Value *FNeg = Builder.CreateFNeg (CastOp);
4863
+ return new BitCastInst (FNeg, I.getType ());
4864
+ }
4866
4865
}
4867
4866
}
4868
4867
0 commit comments