[IRBuilder] Move CreateNeg() to fold API

Remove the CreateNeg() method from IRBuilderFolder and base it on
CreateSub(0, V) instead, which will call FoldNoWrapBinaryOp().

May not be NFC if InstSimplifyFolder is used.
This commit is contained in:
Nikita Popov 2022-07-01 14:54:10 +02:00
parent 5c8021777c
commit 21933b2f7f
6 changed files with 4 additions and 32 deletions

View File

@ -111,10 +111,6 @@ public:
// Unary Operators
//===--------------------------------------------------------------------===//
Value *CreateNeg(Constant *C, bool HasNUW = false,
bool HasNSW = false) const override {
return ConstFolder.CreateNeg(C, HasNUW, HasNSW);
}
Value *CreateFNeg(Constant *C) const override {
return ConstFolder.CreateFNeg(C);
}

View File

@ -168,10 +168,6 @@ public:
// Unary Operators
//===--------------------------------------------------------------------===//
Constant *CreateNeg(Constant *C,
bool HasNUW = false, bool HasNSW = false) const override {
return Fold(ConstantExpr::getNeg(C, HasNUW, HasNSW));
}
Constant *CreateFNeg(Constant *C) const override {
return Fold(ConstantExpr::getFNeg(C));
}

View File

@ -158,11 +158,6 @@ public:
// Unary Operators
//===--------------------------------------------------------------------===//
Constant *CreateNeg(Constant *C,
bool HasNUW = false, bool HasNSW = false) const override {
return ConstantExpr::getNeg(C, HasNUW, HasNSW);
}
Constant *CreateFNeg(Constant *C) const override {
return ConstantExpr::getFNeg(C);
}

View File

@ -1572,14 +1572,10 @@ public:
Optional<RoundingMode> Rounding = None,
Optional<fp::ExceptionBehavior> Except = None);
Value *CreateNeg(Value *V, const Twine &Name = "",
bool HasNUW = false, bool HasNSW = false) {
if (auto *VC = dyn_cast<Constant>(V))
return Insert(Folder.CreateNeg(VC, HasNUW, HasNSW), Name);
BinaryOperator *BO = Insert(BinaryOperator::CreateNeg(V), Name);
if (HasNUW) BO->setHasNoUnsignedWrap();
if (HasNSW) BO->setHasNoSignedWrap();
return BO;
Value *CreateNeg(Value *V, const Twine &Name = "", bool HasNUW = false,
bool HasNSW = false) {
return CreateSub(Constant::getNullValue(V->getType()), V, Name, HasNUW,
HasNSW);
}
Value *CreateNSWNeg(Value *V, const Twine &Name = "") {

View File

@ -71,8 +71,6 @@ public:
// Unary Operators
//===--------------------------------------------------------------------===//
virtual Value *CreateNeg(Constant *C,
bool HasNUW = false, bool HasNSW = false) const = 0;
virtual Value *CreateFNeg(Constant *C) const = 0;
virtual Value *CreateUnOp(Instruction::UnaryOps Opc, Constant *C) const = 0;

View File

@ -106,15 +106,6 @@ public:
// Unary Operators
//===--------------------------------------------------------------------===//
Instruction *CreateNeg(Constant *C,
bool HasNUW = false,
bool HasNSW = false) const override {
BinaryOperator *BO = BinaryOperator::CreateNeg(C);
if (HasNUW) BO->setHasNoUnsignedWrap();
if (HasNSW) BO->setHasNoSignedWrap();
return BO;
}
Instruction *CreateFNeg(Constant *C) const override {
return UnaryOperator::CreateFNeg(C);
}