mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 03:33:20 +01:00
Consider expression "0.0 - X" as the negation of X if
- this expression is explicitly marked no-signed-zero, or - no-signed-zero of this expression can be derived from some context. llvm-svn: 171922
This commit is contained in:
parent
11f9d2e631
commit
2dc1fb7889
@ -61,6 +61,9 @@ public:
|
||||
/// by getZeroValueForNegation.
|
||||
bool isNegativeZeroValue() const;
|
||||
|
||||
/// Return true if the value is negative zero or null value.
|
||||
bool isZeroValue() const;
|
||||
|
||||
/// canTrap - Return true if evaluation of this constant could trap. This is
|
||||
/// true for things like constant expressions that could divide by zero.
|
||||
bool canTrap() const;
|
||||
|
@ -309,7 +309,7 @@ public:
|
||||
/// NEG, FNeg, or NOT instruction.
|
||||
///
|
||||
static bool isNeg(const Value *V);
|
||||
static bool isFNeg(const Value *V);
|
||||
static bool isFNeg(const Value *V, bool IgnoreZeroSign=false);
|
||||
static bool isNot(const Value *V);
|
||||
|
||||
/// getNegArgument, getNotArgument - Helper functions to extract the
|
||||
|
@ -51,6 +51,15 @@ bool Constant::isNegativeZeroValue() const {
|
||||
return isNullValue();
|
||||
}
|
||||
|
||||
bool Constant::isZeroValue() const {
|
||||
// Floating point values have an explicit -0.0 value.
|
||||
if (const ConstantFP *CFP = dyn_cast<ConstantFP>(this))
|
||||
return CFP->isZero();
|
||||
|
||||
// Otherwise, just use +0.0.
|
||||
return isNullValue();
|
||||
}
|
||||
|
||||
bool Constant::isNullValue() const {
|
||||
// 0 is null.
|
||||
if (const ConstantInt *CI = dyn_cast<ConstantInt>(this))
|
||||
|
@ -1926,11 +1926,14 @@ bool BinaryOperator::isNeg(const Value *V) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BinaryOperator::isFNeg(const Value *V) {
|
||||
bool BinaryOperator::isFNeg(const Value *V, bool IgnoreZeroSign) {
|
||||
if (const BinaryOperator *Bop = dyn_cast<BinaryOperator>(V))
|
||||
if (Bop->getOpcode() == Instruction::FSub)
|
||||
if (Constant* C = dyn_cast<Constant>(Bop->getOperand(0)))
|
||||
return C->isNegativeZeroValue();
|
||||
if (Constant* C = dyn_cast<Constant>(Bop->getOperand(0))) {
|
||||
if (!IgnoreZeroSign)
|
||||
IgnoreZeroSign = cast<Instruction>(V)->hasNoSignedZeros();
|
||||
return !IgnoreZeroSign ? C->isNegativeZeroValue() : C->isZeroValue();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -211,7 +211,7 @@ public:
|
||||
private:
|
||||
bool ShouldChangeType(Type *From, Type *To) const;
|
||||
Value *dyn_castNegVal(Value *V) const;
|
||||
Value *dyn_castFNegVal(Value *V) const;
|
||||
Value *dyn_castFNegVal(Value *V, bool NoSignedZero=false) const;
|
||||
Type *FindElementAtOffset(Type *Ty, int64_t Offset,
|
||||
SmallVectorImpl<Value*> &NewIndices);
|
||||
Instruction *FoldOpIntoSelect(Instruction &Op, SelectInst *SI);
|
||||
|
@ -516,8 +516,8 @@ Value *InstCombiner::dyn_castNegVal(Value *V) const {
|
||||
// instruction if the LHS is a constant negative zero (which is the 'negate'
|
||||
// form).
|
||||
//
|
||||
Value *InstCombiner::dyn_castFNegVal(Value *V) const {
|
||||
if (BinaryOperator::isFNeg(V))
|
||||
Value *InstCombiner::dyn_castFNegVal(Value *V, bool IgnoreZeroSign) const {
|
||||
if (BinaryOperator::isFNeg(V, IgnoreZeroSign))
|
||||
return BinaryOperator::getFNegArgument(V);
|
||||
|
||||
// Constants can be considered to be negated values if they can be folded.
|
||||
|
@ -243,5 +243,16 @@ define float @fmul5(float %f1, float %f2) {
|
||||
; CHECK: fdiv fast float %f1, 0x47E8000000000000
|
||||
}
|
||||
|
||||
|
||||
|
||||
; =========================================================================
|
||||
;
|
||||
; Testing-cases about negation
|
||||
;
|
||||
; =========================================================================
|
||||
define float @fneg1(float %f1, float %f2) {
|
||||
%sub = fsub float -0.000000e+00, %f1
|
||||
%sub1 = fsub nsz float 0.000000e+00, %f2
|
||||
%mul = fmul float %sub, %sub1
|
||||
ret float %mul
|
||||
; CHECK: @fneg1
|
||||
; CHECK: fmul float %f1, %f2
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user