[llvm] 6a19cb8 - [ConstantFold] Support pointers in reinterpret load folding
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 21 00:15:36 PST 2022
Author: Nikita Popov
Date: 2022-01-21T09:13:37+01:00
New Revision: 6a19cb837c9b2ca14642bb0a8f1234903e4430d0
URL: https://github.com/llvm/llvm-project/commit/6a19cb837c9b2ca14642bb0a8f1234903e4430d0
DIFF: https://github.com/llvm/llvm-project/commit/6a19cb837c9b2ca14642bb0a8f1234903e4430d0.diff
LOG: [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.
Added:
Modified:
llvm/lib/Analysis/ConstantFolding.cpp
llvm/test/Transforms/InstSimplify/ConstProp/loads.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index d42086a10ee14..c834ecf107915 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -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(
diff --git a/llvm/test/Transforms/InstSimplify/ConstProp/loads.ll b/llvm/test/Transforms/InstSimplify/ConstProp/loads.ll
index 65daa324f7468..990063be0468e 100644
--- a/llvm/test/Transforms/InstSimplify/ConstProp/loads.ll
+++ b/llvm/test/Transforms/InstSimplify/ConstProp/loads.ll
@@ -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
More information about the llvm-commits
mailing list