[llvm] 05cd9a0 - [ConstantFold] Simplify type check in reinterpret load folding (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 21 00:08:52 PST 2022
Author: Nikita Popov
Date: 2022-01-21T09:06:35+01:00
New Revision: 05cd9a0596d8d2cc4fdb1d1dfa0957968aceaf92
URL: https://github.com/llvm/llvm-project/commit/05cd9a0596d8d2cc4fdb1d1dfa0957968aceaf92
DIFF: https://github.com/llvm/llvm-project/commit/05cd9a0596d8d2cc4fdb1d1dfa0957968aceaf92.diff
LOG: [ConstantFold] Simplify type check in reinterpret load folding (NFC)
Keep a list of allowed types, but then always construct the map
type the same way. We need an integer with the same width as the
original type.
Added:
Modified:
llvm/lib/Analysis/ConstantFolding.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 253a7243bcf59..d42086a10ee14 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -553,23 +553,16 @@ Constant *FoldReinterpretLoadFromConst(Constant *C, Type *LoadTy,
// If this isn't an integer load we can't fold it directly.
if (!IntType) {
- // If this is a float/double load, we can try folding it as an int32/64 load
- // and then bitcast the result. This can be useful for union cases. Note
+ // If this is a non-integer load, we can try folding it as an int load and
+ // then bitcast the result. This can be useful for union cases. Note
// that address spaces don't matter here since we're not going to result in
// an actual new load.
- Type *MapTy;
- if (LoadTy->isHalfTy())
- MapTy = Type::getInt16Ty(C->getContext());
- else if (LoadTy->isFloatTy())
- MapTy = Type::getInt32Ty(C->getContext());
- else if (LoadTy->isDoubleTy())
- MapTy = Type::getInt64Ty(C->getContext());
- else if (LoadTy->isVectorTy()) {
- MapTy = PointerType::getIntNTy(
- C->getContext(), DL.getTypeSizeInBits(LoadTy).getFixedSize());
- } else
+ if (!LoadTy->isHalfTy() && !LoadTy->isFloatTy() && !LoadTy->isDoubleTy() &&
+ !LoadTy->isVectorTy())
return nullptr;
+ Type *MapTy = Type::getIntNTy(
+ C->getContext(), DL.getTypeSizeInBits(LoadTy).getFixedSize());
if (Constant *Res = FoldReinterpretLoadFromConst(C, MapTy, Offset, DL)) {
if (Res->isNullValue() && !LoadTy->isX86_MMXTy() &&
!LoadTy->isX86_AMXTy())
More information about the llvm-commits
mailing list