[llvm] a1403dc - [ConstantFolding] Avoid use of ConstantExpr::getOr() (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 24 08:00:45 PDT 2023


Author: Nikita Popov
Date: 2023-07-24T17:00:38+02:00
New Revision: a1403dc3d077e6bba0cbe9dbbbfc7aef4c7ad6b2

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

LOG: [ConstantFolding] Avoid use of ConstantExpr::getOr() (NFC)

Constant folding cannot fail here, because we're really working
on plain integers. It might be better to make all of this work
on APInts instead of Constants.

Added: 
    

Modified: 
    llvm/lib/Analysis/ConstantFolding.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 08c60b42ae79c1..fbc627542b234a 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -235,7 +235,8 @@ Constant *FoldBitCast(Constant *C, Type *DestTy, const DataLayout &DL) {
         ShiftAmt += isLittleEndian ? SrcBitSize : -SrcBitSize;
 
         // Mix it in.
-        Elt = ConstantExpr::getOr(Elt, Src);
+        Elt = ConstantFoldBinaryOpOperands(Instruction::Or, Elt, Src, DL);
+        assert(Elt && "Constant folding cannot fail on plain integers");
       }
       Result.push_back(Elt);
     }


        


More information about the llvm-commits mailing list