Skip to content

Commit

Permalink
[ConstantFold] Support pointers in reinterpret load folding
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikic committed Jan 21, 2022
1 parent 05cd9a0 commit 6a19cb8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/ConstantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 5 additions & 3 deletions llvm/test/Transforms/InstSimplify/ConstProp/loads.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6a19cb8

Please sign in to comment.