[llvm] 3c80d24 - [NFC] Simplify logic in ConstantFold

Guillaume Chatelet via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 3 07:41:10 PST 2023


Author: Guillaume Chatelet
Date: 2023-02-03T15:40:55Z
New Revision: 3c80d24a4b24c878068d2bb5d8a650af027598cf

URL: https://github.com/llvm/llvm-project/commit/3c80d24a4b24c878068d2bb5d8a650af027598cf
DIFF: https://github.com/llvm/llvm-project/commit/3c80d24a4b24c878068d2bb5d8a650af027598cf.diff

LOG: [NFC] Simplify logic in ConstantFold

Differential Revision: https://reviews.llvm.org/D143271

Added: 
    

Modified: 
    llvm/lib/IR/ConstantFold.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 18f481a9f1c88..7af33a70d3276 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -1053,7 +1053,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1,
             isa<GlobalValue>(CE1->getOperand(0))) {
           GlobalValue *GV = cast<GlobalValue>(CE1->getOperand(0));
 
-          MaybeAlign GVAlign;
+          Align GVAlign; // defaults to 1
 
           if (Module *TheModule = GV->getParent()) {
             const DataLayout &DL = TheModule->getDataLayout();
@@ -1073,14 +1073,14 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1,
           } else if (isa<Function>(GV)) {
             // Without a datalayout we have to assume the worst case: that the
             // function pointer isn't aligned at all.
-            GVAlign = std::nullopt;
+            GVAlign = Align(1);
           } else if (isa<GlobalVariable>(GV)) {
-            GVAlign = cast<GlobalVariable>(GV)->getAlign();
+            GVAlign = cast<GlobalVariable>(GV)->getAlign().valueOrOne();
           }
 
-          if (GVAlign && *GVAlign > 1) {
+          if (GVAlign > 1) {
             unsigned DstWidth = CI2->getType()->getBitWidth();
-            unsigned SrcWidth = std::min(DstWidth, Log2(*GVAlign));
+            unsigned SrcWidth = std::min(DstWidth, Log2(GVAlign));
             APInt BitsNotSet(APInt::getLowBitsSet(DstWidth, SrcWidth));
 
             // If checking bits we know are clear, return zero.


        


More information about the llvm-commits mailing list