[llvm] 693b1f1 - [InstCombine] Skip some GEP folds under opaque pointers
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 28 06:35:46 PST 2021
Author: Nikita Popov
Date: 2021-12-28T15:32:11+01:00
New Revision: 693b1f1e1bd1bc2060ea8cfd2129cb0123397a8c
URL: https://github.com/llvm/llvm-project/commit/693b1f1e1bd1bc2060ea8cfd2129cb0123397a8c
DIFF: https://github.com/llvm/llvm-project/commit/693b1f1e1bd1bc2060ea8cfd2129cb0123397a8c.diff
LOG: [InstCombine] Skip some GEP folds under opaque pointers
In their current form, these folds are fundamentally incompatible
with opaque pointers. We should add a separate set of folds for
the canonicalization of the GEP source type. For now, skip these
folds.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/opaque-ptr.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index aaf07f25e4748..c66b39fc7927b 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -2244,7 +2244,11 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) {
Value *StrippedPtr = PtrOp->stripPointerCasts();
PointerType *StrippedPtrTy = cast<PointerType>(StrippedPtr->getType());
- if (StrippedPtr != PtrOp) {
+ // TODO: The basic approach of these folds is not compatible with opaque
+ // pointers, because we can't use bitcasts as a hint for a desirable GEP
+ // type. Instead, we should perform canonicalization directly on the GEP
+ // type. For now, skip these.
+ if (StrippedPtr != PtrOp && !StrippedPtrTy->isOpaque()) {
bool HasZeroPointerIndex = false;
Type *StrippedPtrEltTy = StrippedPtrTy->getElementType();
diff --git a/llvm/test/Transforms/InstCombine/opaque-ptr.ll b/llvm/test/Transforms/InstCombine/opaque-ptr.ll
index 035b50588f549..1d73ab1689399 100644
--- a/llvm/test/Transforms/InstCombine/opaque-ptr.ll
+++ b/llvm/test/Transforms/InstCombine/opaque-ptr.ll
@@ -263,3 +263,14 @@ bb:
bb2:
ret ptr %RHS
}
+
+define ptr addrspace(1) @gep_of_addrspace_cast(ptr %ptr) {
+; CHECK-LABEL: @gep_of_addrspace_cast(
+; CHECK-NEXT: [[CAST1:%.*]] = addrspacecast ptr [[PTR:%.*]] to ptr addrspace(1)
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i32, ptr addrspace(1) [[CAST1]], i64 1
+; CHECK-NEXT: ret ptr addrspace(1) [[GEP]]
+;
+ %cast1 = addrspacecast ptr %ptr to ptr addrspace(1)
+ %gep = getelementptr inbounds i32, ptr addrspace(1) %cast1, i64 1
+ ret ptr addrspace(1) %gep
+}
More information about the llvm-commits
mailing list