[IRBuilder] Move CreateNeg() to fold API
authorNikita Popov <npopov@redhat.com>
Fri, 1 Jul 2022 12:54:10 +0000 (14:54 +0200)
committerNikita Popov <npopov@redhat.com>
Fri, 1 Jul 2022 12:54:10 +0000 (14:54 +0200)
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.

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

index 53fd06c..d4ea7d7 100644 (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);
   }
index 1d9b103..3a7218b 100644 (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));
   }
index 320e784..5e7ddb9 100644 (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);
   }
index 885da3c..d8f0893 100644 (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 = "") {
index 258e0d8..9505f1e 100644 (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;
 
index cf6d9cb..4e9f772 100644 (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);
   }