Skip to content

Commit fff3484

Browse files
committed
[InstCombine] Reduce changes
1 parent 925dfd0 commit fff3484

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2637,18 +2637,18 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator &I) {
26372637
// This is a generous interpretation for noimplicitfloat, this is not a true
26382638
// floating-point operation.
26392639
//
2640-
// Assumes any floating point type has the sign bit in the high bit.
26412640
// TODO: Unify with APInt matcher. This version allows undef unlike m_APInt
26422641
Value *CastOp;
26432642
if (match(Op0, m_ElementWiseBitCast(m_Value(CastOp))) &&
2644-
CastOp->getType()->isFPOrFPVectorTy() &&
2645-
APFloat::hasSignBitInMSB(
2646-
CastOp->getType()->getScalarType()->getFltSemantics()) &&
26472643
match(Op1, m_MaxSignedValue()) &&
26482644
!Builder.GetInsertBlock()->getParent()->hasFnAttribute(
26492645
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+
}
26522652
}
26532653

26542654
// and(shl(zext(X), Y), SignMask) -> and(sext(X), SignMask)
@@ -4047,21 +4047,20 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
40474047
// the number of instructions. This is still probably a better canonical form
40484048
// as it enables FP value tracking.
40494049
//
4050-
// Assumes any floating point type has the sign bit in the high bit.
4051-
//
40524050
// This is generous interpretation of noimplicitfloat, this is not a true
40534051
// floating-point operation.
40544052
Value *CastOp;
40554053
if (match(Op0, m_ElementWiseBitCast(m_Value(CastOp))) &&
4056-
CastOp->getType()->isFPOrFPVectorTy() &&
4057-
APFloat::hasSignBitInMSB(
4058-
CastOp->getType()->getScalarType()->getFltSemantics()) &&
40594054
match(Op1, m_SignMask()) &&
40604055
!Builder.GetInsertBlock()->getParent()->hasFnAttribute(
40614056
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+
}
40654064
}
40664065

40674066
// (X & C1) | C2 -> X & (C1 | C2) iff (X & C2) == C2
@@ -4851,18 +4850,18 @@ Instruction *InstCombinerImpl::visitXor(BinaryOperator &I) {
48514850
// This is generous interpretation of noimplicitfloat, this is not a true
48524851
// floating-point operation.
48534852
//
4854-
// Assumes any floating point type has the sign bit in the high bit.
48554853
// TODO: Unify with APInt matcher. This version allows undef unlike m_APInt
48564854
Value *CastOp;
48574855
if (match(Op0, m_ElementWiseBitCast(m_Value(CastOp))) &&
4858-
CastOp->getType()->isFPOrFPVectorTy() &&
4859-
APFloat::hasSignBitInMSB(
4860-
CastOp->getType()->getScalarType()->getFltSemantics()) &&
48614856
match(Op1, m_SignMask()) &&
48624857
!Builder.GetInsertBlock()->getParent()->hasFnAttribute(
48634858
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+
}
48664865
}
48674866
}
48684867

0 commit comments

Comments
 (0)