[clang] fb2bdbb - [CodeGen] Avoid use of ConstantExpr::getZExt() (NFC)

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 28 07:45:39 PDT 2023


Author: Nikita Popov
Date: 2023-09-28T16:45:31+02:00
New Revision: fb2bdbb83d3913d9d32b28c1de3f3d8b4e6dfc8a

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

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

Use the constant folding API instead. In preparation for dropping
zext constant expressions.

Added: 
    

Modified: 
    clang/lib/CodeGen/CGExprConstant.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp
index 2c847f0bb13fd2e..9b67a8b3335a165 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -25,6 +25,7 @@
 #include "clang/Basic/Builtins.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/Sequence.h"
+#include "llvm/Analysis/ConstantFolding.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Function.h"
@@ -1761,7 +1762,10 @@ llvm::Constant *ConstantEmitter::emitForMemory(CodeGenModule &CGM,
   // Zero-extend bool.
   if (C->getType()->isIntegerTy(1) && !destType->isBitIntType()) {
     llvm::Type *boolTy = CGM.getTypes().ConvertTypeForMem(destType);
-    return llvm::ConstantExpr::getZExt(C, boolTy);
+    llvm::Constant *Res = llvm::ConstantFoldCastOperand(
+        llvm::Instruction::ZExt, C, boolTy, CGM.getDataLayout());
+    assert(Res && "Constant folding must succeed");
+    return Res;
   }
 
   return C;


        


More information about the cfe-commits mailing list