Skip to content

Commit 05cd9a0

Browse files
committed
[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.
1 parent a99e06a commit 05cd9a0

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -553,23 +553,16 @@ Constant *FoldReinterpretLoadFromConst(Constant *C, Type *LoadTy,
553553

554554
// If this isn't an integer load we can't fold it directly.
555555
if (!IntType) {
556-
// If this is a float/double load, we can try folding it as an int32/64 load
557-
// and then bitcast the result. This can be useful for union cases. Note
556+
// If this is a non-integer load, we can try folding it as an int load and
557+
// then bitcast the result. This can be useful for union cases. Note
558558
// that address spaces don't matter here since we're not going to result in
559559
// an actual new load.
560-
Type *MapTy;
561-
if (LoadTy->isHalfTy())
562-
MapTy = Type::getInt16Ty(C->getContext());
563-
else if (LoadTy->isFloatTy())
564-
MapTy = Type::getInt32Ty(C->getContext());
565-
else if (LoadTy->isDoubleTy())
566-
MapTy = Type::getInt64Ty(C->getContext());
567-
else if (LoadTy->isVectorTy()) {
568-
MapTy = PointerType::getIntNTy(
569-
C->getContext(), DL.getTypeSizeInBits(LoadTy).getFixedSize());
570-
} else
560+
if (!LoadTy->isHalfTy() && !LoadTy->isFloatTy() && !LoadTy->isDoubleTy() &&
561+
!LoadTy->isVectorTy())
571562
return nullptr;
572563

564+
Type *MapTy = Type::getIntNTy(
565+
C->getContext(), DL.getTypeSizeInBits(LoadTy).getFixedSize());
573566
if (Constant *Res = FoldReinterpretLoadFromConst(C, MapTy, Offset, DL)) {
574567
if (Res->isNullValue() && !LoadTy->isX86_MMXTy() &&
575568
!LoadTy->isX86_AMXTy())

0 commit comments

Comments
 (0)