[llvm] 21933b2 - [IRBuilder] Move CreateNeg() to fold API
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 1 05:56:12 PDT 2022
Author: Nikita Popov
Date: 2022-07-01T14:54:10+02:00
New Revision: 21933b2f7f02cbbf67703d50da660ffc8119f84a
URL: https://github.com/llvm/llvm-project/commit/21933b2f7f02cbbf67703d50da660ffc8119f84a
DIFF: https://github.com/llvm/llvm-project/commit/21933b2f7f02cbbf67703d50da660ffc8119f84a.diff
LOG: [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.
Added:
Modified:
llvm/include/llvm/Analysis/InstSimplifyFolder.h
llvm/include/llvm/Analysis/TargetFolder.h
llvm/include/llvm/IR/ConstantFolder.h
llvm/include/llvm/IR/IRBuilder.h
llvm/include/llvm/IR/IRBuilderFolder.h
llvm/include/llvm/IR/NoFolder.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/InstSimplifyFolder.h b/llvm/include/llvm/Analysis/InstSimplifyFolder.h
index 53fd06c8b0cb..d4ea7d73ec92 100644
--- a/llvm/include/llvm/Analysis/InstSimplifyFolder.h
+++ b/llvm/include/llvm/Analysis/InstSimplifyFolder.h
@@ -111,10 +111,6 @@ class InstSimplifyFolder final : public IRBuilderFolder {
// 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);
}
diff --git a/llvm/include/llvm/Analysis/TargetFolder.h b/llvm/include/llvm/Analysis/TargetFolder.h
index 1d9b103e2acc..3a7218b10b97 100644
--- a/llvm/include/llvm/Analysis/TargetFolder.h
+++ b/llvm/include/llvm/Analysis/TargetFolder.h
@@ -168,10 +168,6 @@ class TargetFolder final : public IRBuilderFolder {
// 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));
}
diff --git a/llvm/include/llvm/IR/ConstantFolder.h b/llvm/include/llvm/IR/ConstantFolder.h
index 320e784b58af..5e7ddb9aa673 100644
--- a/llvm/include/llvm/IR/ConstantFolder.h
+++ b/llvm/include/llvm/IR/ConstantFolder.h
@@ -158,11 +158,6 @@ class ConstantFolder final : public IRBuilderFolder {
// 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);
}
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 885da3c2c9c7..d8f08934b3d6 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -1572,14 +1572,10 @@ class IRBuilderBase {
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 = "") {
diff --git a/llvm/include/llvm/IR/IRBuilderFolder.h b/llvm/include/llvm/IR/IRBuilderFolder.h
index 258e0d80ac90..9505f1e3be2a 100644
--- a/llvm/include/llvm/IR/IRBuilderFolder.h
+++ b/llvm/include/llvm/IR/IRBuilderFolder.h
@@ -71,8 +71,6 @@ class IRBuilderFolder {
// 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;
diff --git a/llvm/include/llvm/IR/NoFolder.h b/llvm/include/llvm/IR/NoFolder.h
index cf6d9cb1f479..4e9f772dfdb6 100644
--- a/llvm/include/llvm/IR/NoFolder.h
+++ b/llvm/include/llvm/IR/NoFolder.h
@@ -106,15 +106,6 @@ class NoFolder final : public IRBuilderFolder {
// 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);
}
More information about the llvm-commits
mailing list