-
Notifications
You must be signed in to change notification settings - Fork 15.2k
InstCombine: Check GEP operand is available #160438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InstCombine: Check GEP operand is available #160438
Conversation
Logic copied from the select case. Fixes #160302
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-backend-amdgpu Author: Matt Arsenault (arsenm) ChangesLogic copied from the select case. Fixes #160302 Full diff: https://github.com/llvm/llvm-project/pull/160438.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index 53e77e6cc5c31..9491610190c10 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -338,8 +338,18 @@ bool PointerReplacer::collectUsers() {
if (!TryPushInstOperand(TrueInst) || !TryPushInstOperand(FalseInst))
return false;
} else if (auto *GEP = dyn_cast<GetElementPtrInst>(Inst)) {
- UsersToReplace.insert(GEP);
- PushUsersToWorklist(GEP);
+ auto *PtrOp = dyn_cast<Instruction>(GEP->getPointerOperand());
+ if (!PtrOp)
+ return false;
+ if (isAvailable(PtrOp)) {
+ UsersToReplace.insert(GEP);
+ PushUsersToWorklist(GEP);
+ continue;
+ }
+
+ Worklist.emplace_back(GEP);
+ if (!TryPushInstOperand(PtrOp))
+ return false;
} else if (auto *MI = dyn_cast<MemTransferInst>(Inst)) {
if (MI->isVolatile())
return false;
diff --git a/llvm/test/Transforms/InstCombine/AMDGPU/ptr-replace-alloca.ll b/llvm/test/Transforms/InstCombine/AMDGPU/ptr-replace-alloca.ll
index beb84362b7f92..90877be255e0f 100644
--- a/llvm/test/Transforms/InstCombine/AMDGPU/ptr-replace-alloca.ll
+++ b/llvm/test/Transforms/InstCombine/AMDGPU/ptr-replace-alloca.ll
@@ -109,4 +109,23 @@ bb:
ret void
}
+@global = external addrspace(1) constant [16 x float], align 64
+
+define float @issue160302(i1 %cond, ptr addrspace(5) %arg) {
+; CHECK-LABEL: define float @issue160302(
+; CHECK-SAME: i1 [[COND:%.*]], ptr addrspace(5) [[ARG:%.*]]) {
+; CHECK-NEXT: [[AGG_TMP2_I4:%.*]] = alloca [16 x float], align 64, addrspace(5)
+; CHECK-NEXT: [[SELECT_PTR:%.*]] = select i1 [[COND]], ptr addrspace(5) [[AGG_TMP2_I4]], ptr addrspace(5) [[ARG]]
+; CHECK-NEXT: [[COND_I:%.*]] = load float, ptr addrspace(5) [[SELECT_PTR]], align 4
+; CHECK-NEXT: ret float [[COND_I]]
+;
+ %agg.tmp2.i4 = alloca [16 x float], align 64, addrspace(5)
+ call void @llvm.memcpy.p5.p1.i64(ptr addrspace(5) %agg.tmp2.i4, ptr addrspace(1) @global, i64 0, i1 false)
+ %m_Data.i14.i = getelementptr [16 x float], ptr addrspace(5) %agg.tmp2.i4, i32 0, i32 0
+ %gep = getelementptr [16 x float], ptr addrspace(5) %arg, i32 0, i32 0
+ %select.ptr = select i1 %cond, ptr addrspace(5) %m_Data.i14.i, ptr addrspace(5) %gep
+ %cond.i = load float, ptr addrspace(5) %select.ptr, align 4
+ ret float %cond.i
+}
+
declare void @llvm.memcpy.p5.p4.i64(ptr addrspace(5) noalias writeonly captures(none), ptr addrspace(4) noalias readonly captures(none), i64, i1 immarg) #0
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/51/builds/24113 Here is the relevant piece of the build log for the reference
|
Logic copied from the select case. Fixes llvm#160302
Logic copied from the select case.
Fixes #160302