[IRBuilder] Move CreateNot() to fold API
authorNikita Popov <npopov@redhat.com>
Fri, 1 Jul 2022 12:47:56 +0000 (14:47 +0200)
committerNikita Popov <npopov@redhat.com>
Fri, 1 Jul 2022 12:48:57 +0000 (14:48 +0200)
Drop the IRBuilderFolder method entirely and base this on
CreateXor(V, -1) instead, so this will now go through FoldBinOp.

May not be NFC if the InstSimplifyBuilder 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 33b6f12..53fd06c 100644 (file)
@@ -118,9 +118,6 @@ public:
   Value *CreateFNeg(Constant *C) const override {
     return ConstFolder.CreateFNeg(C);
   }
-  Value *CreateNot(Constant *C) const override {
-    return ConstFolder.CreateNot(C);
-  }
 
   Value *CreateUnOp(Instruction::UnaryOps Opc, Constant *C) const override {
     return ConstFolder.CreateUnOp(Opc, C);
index 93ac33c..1d9b103 100644 (file)
@@ -175,9 +175,6 @@ public:
   Constant *CreateFNeg(Constant *C) const override {
     return Fold(ConstantExpr::getFNeg(C));
   }
-  Constant *CreateNot(Constant *C) const override {
-    return Fold(ConstantExpr::getNot(C));
-  }
 
   Constant *CreateUnOp(Instruction::UnaryOps Opc, Constant *C) const override {
     return Fold(ConstantExpr::get(Opc, C));
index 1243043..320e784 100644 (file)
@@ -167,10 +167,6 @@ public:
     return ConstantExpr::getFNeg(C);
   }
 
-  Constant *CreateNot(Constant *C) const override {
-    return ConstantExpr::getNot(C);
-  }
-
   Constant *CreateUnOp(Instruction::UnaryOps Opc, Constant *C) const override {
     return ConstantExpr::get(Opc, C);
   }
index 902d945..885da3c 100644 (file)
@@ -1610,9 +1610,7 @@ public:
   }
 
   Value *CreateNot(Value *V, const Twine &Name = "") {
-    if (auto *VC = dyn_cast<Constant>(V))
-      return Insert(Folder.CreateNot(VC), Name);
-    return Insert(BinaryOperator::CreateNot(V), Name);
+    return CreateXor(V, Constant::getAllOnesValue(V->getType()), Name);
   }
 
   Value *CreateUnOp(Instruction::UnaryOps Opc,
index 1cc5993..258e0d8 100644 (file)
@@ -74,7 +74,6 @@ public:
   virtual Value *CreateNeg(Constant *C,
                            bool HasNUW = false, bool HasNSW = false) const = 0;
   virtual Value *CreateFNeg(Constant *C) const = 0;
-  virtual Value *CreateNot(Constant *C) const = 0;
   virtual Value *CreateUnOp(Instruction::UnaryOps Opc, Constant *C) const = 0;
 
   //===--------------------------------------------------------------------===//
index 8f3f1d6..cf6d9cb 100644 (file)
@@ -119,10 +119,6 @@ public:
     return UnaryOperator::CreateFNeg(C);
   }
 
-  Instruction *CreateNot(Constant *C) const override {
-    return BinaryOperator::CreateNot(C);
-  }
-
   Instruction *CreateUnOp(Instruction::UnaryOps Opc,
                           Constant *C) const override {
     return UnaryOperator::Create(Opc, C);