[llvm] 0f0e699 - [ConstantFold] Disable gep of array bitcast fold with opaque pointers
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 27 02:52:59 PST 2022
Author: Nikita Popov
Date: 2022-01-27T11:52:52+01:00
New Revision: 0f0e699776d731f3aae358428e56f4ae3968abe8
URL: https://github.com/llvm/llvm-project/commit/0f0e699776d731f3aae358428e56f4ae3968abe8
DIFF: https://github.com/llvm/llvm-project/commit/0f0e699776d731f3aae358428e56f4ae3968abe8.diff
LOG: [ConstantFold] Disable gep of array bitcast fold with opaque pointers
Once again, this fold is meaningless with opaque pointers, as there
is no pointer element type to canonicalize. At some point, we may
want to do GEP type canonicalizations.
Added:
Modified:
llvm/lib/IR/ConstantFold.cpp
llvm/test/Transforms/InstCombine/opaque-ptr.ll
Removed:
################################################################################
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 1cd95cd5d4c8e..622a984be22c7 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -2096,11 +2096,12 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C,
PointerType *SrcPtrTy =
dyn_cast<PointerType>(CE->getOperand(0)->getType());
PointerType *DstPtrTy = dyn_cast<PointerType>(CE->getType());
- if (SrcPtrTy && DstPtrTy) {
+ if (SrcPtrTy && DstPtrTy && !SrcPtrTy->isOpaque() &&
+ !DstPtrTy->isOpaque()) {
ArrayType *SrcArrayTy =
- dyn_cast<ArrayType>(SrcPtrTy->getPointerElementType());
+ dyn_cast<ArrayType>(SrcPtrTy->getNonOpaquePointerElementType());
ArrayType *DstArrayTy =
- dyn_cast<ArrayType>(DstPtrTy->getPointerElementType());
+ dyn_cast<ArrayType>(DstPtrTy->getNonOpaquePointerElementType());
if (SrcArrayTy && DstArrayTy
&& SrcArrayTy->getElementType() == DstArrayTy->getElementType()
&& SrcPtrTy->getAddressSpace() == DstPtrTy->getAddressSpace())
diff --git a/llvm/test/Transforms/InstCombine/opaque-ptr.ll b/llvm/test/Transforms/InstCombine/opaque-ptr.ll
index 1d73ab1689399..0b48ce523eed9 100644
--- a/llvm/test/Transforms/InstCombine/opaque-ptr.ll
+++ b/llvm/test/Transforms/InstCombine/opaque-ptr.ll
@@ -91,6 +91,13 @@ define ptr @gep_constexpr_2(ptr %a) {
ret ptr getelementptr (i8, ptr bitcast (i8* @g to ptr), i32 3)
}
+define ptr addrspace(1) @gep_constexpr_3(ptr %a) {
+; CHECK-LABEL: @gep_constexpr_3(
+; CHECK-NEXT: ret ptr addrspace(1) getelementptr (i8, ptr addrspace(1) addrspacecast (ptr @g to ptr addrspace(1)), i64 3)
+;
+ ret ptr addrspace(1) getelementptr ([0 x i8], ptr addrspace(1) addrspacecast (i8* @g to ptr addrspace(1)), i64 0, i32 3)
+}
+
define ptr @load_bitcast_1(ptr %a) {
; CHECK-LABEL: @load_bitcast_1(
; CHECK-NEXT: [[B1:%.*]] = load ptr, ptr [[A:%.*]], align 8
More information about the llvm-commits
mailing list