[llvm] d6d44d6 - [ConstantFolding] Avoid use of ConstantExpr::getZExt() (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 28 08:13:57 PDT 2023


Author: Nikita Popov
Date: 2023-09-28T17:13:49+02:00
New Revision: d6d44d6f19f2570bf11f1bc9e568a317fe615903

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

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

Use the constant folding API instead, which should always succeed
in this case.

Added: 
    

Modified: 
    llvm/lib/Analysis/ConstantFolding.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index e08d991dc06093f..75c34d884e44aab 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -227,11 +227,16 @@ Constant *FoldBitCast(Constant *C, Type *DestTy, const DataLayout &DL) {
           return ConstantExpr::getBitCast(C, DestTy);
 
         // Zero extend the element to the right size.
-        Src = ConstantExpr::getZExt(Src, Elt->getType());
+        Src = ConstantFoldCastOperand(Instruction::ZExt, Src, Elt->getType(),
+                                      DL);
+        assert(Src && "Constant folding cannot fail on plain integers");
 
         // Shift it to the right place, depending on endianness.
-        Src = ConstantExpr::getShl(Src,
-                                   ConstantInt::get(Src->getType(), ShiftAmt));
+        Src = ConstantFoldBinaryOpOperands(
+            Instruction::Shl, Src, ConstantInt::get(Src->getType(), ShiftAmt),
+            DL);
+        assert(Src && "Constant folding cannot fail on plain integers");
+
         ShiftAmt += isLittleEndian ? SrcBitSize : -SrcBitSize;
 
         // Mix it in.


        


More information about the llvm-commits mailing list