[ConstantFold] Support pointers in reinterpret load folding

Peculiarly, the necessary code to handle pointers (including the
check for non-integral address spaces) is already in place,
because we were already allowing vectors of pointers here, just
not plain pointers.
This commit is contained in:
Nikita Popov 2022-01-20 16:48:19 +01:00
parent 05cd9a0596
commit 6a19cb837c
2 changed files with 6 additions and 4 deletions

View File

@ -558,7 +558,7 @@ Constant *FoldReinterpretLoadFromConst(Constant *C, Type *LoadTy,
// that address spaces don't matter here since we're not going to result in
// an actual new load.
if (!LoadTy->isHalfTy() && !LoadTy->isFloatTy() && !LoadTy->isDoubleTy() &&
!LoadTy->isVectorTy())
!LoadTy->isPointerTy() && !LoadTy->isVectorTy())
return nullptr;
Type *MapTy = Type::getIntNTy(

View File

@ -340,9 +340,11 @@ define i32 @load_all_undef() {
@g_i8_data = constant [16 x i8] c"\01\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
define i64* @load_ptr_from_i8_data() {
; CHECK-LABEL: @load_ptr_from_i8_data(
; CHECK-NEXT: [[V:%.*]] = load i64*, i64** bitcast ([16 x i8]* @g_i8_data to i64**), align 8
; CHECK-NEXT: ret i64* [[V]]
; LE-LABEL: @load_ptr_from_i8_data(
; LE-NEXT: ret i64* inttoptr (i64 1 to i64*)
;
; BE-LABEL: @load_ptr_from_i8_data(
; BE-NEXT: ret i64* inttoptr (i64 72057594037927936 to i64*)
;
%v = load i64*, i64** bitcast ([16 x i8]* @g_i8_data to i64**)
ret i64* %v