Skip to content

Commit 6a19cb8

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

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ Constant *FoldReinterpretLoadFromConst(Constant *C, Type *LoadTy,
558558
// that address spaces don't matter here since we're not going to result in
559559
// an actual new load.
560560
if (!LoadTy->isHalfTy() && !LoadTy->isFloatTy() && !LoadTy->isDoubleTy() &&
561-
!LoadTy->isVectorTy())
561+
!LoadTy->isPointerTy() && !LoadTy->isVectorTy())
562562
return nullptr;
563563

564564
Type *MapTy = Type::getIntNTy(

llvm/test/Transforms/InstSimplify/ConstProp/loads.ll

+5-3
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,11 @@ define i32 @load_all_undef() {
340340
@g_i8_data = constant [16 x i8] c"\01\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
341341

342342
define i64* @load_ptr_from_i8_data() {
343-
; CHECK-LABEL: @load_ptr_from_i8_data(
344-
; CHECK-NEXT: [[V:%.*]] = load i64*, i64** bitcast ([16 x i8]* @g_i8_data to i64**), align 8
345-
; CHECK-NEXT: ret i64* [[V]]
343+
; LE-LABEL: @load_ptr_from_i8_data(
344+
; LE-NEXT: ret i64* inttoptr (i64 1 to i64*)
345+
;
346+
; BE-LABEL: @load_ptr_from_i8_data(
347+
; BE-NEXT: ret i64* inttoptr (i64 72057594037927936 to i64*)
346348
;
347349
%v = load i64*, i64** bitcast ([16 x i8]* @g_i8_data to i64**)
348350
ret i64* %v

0 commit comments

Comments
 (0)