Skip to content

Commit

Permalink
fix runOnImplicitGEP for more than 1 index missing (google#1254)
Browse files Browse the repository at this point in the history
Since runOnGEPFromGEP has been supported more cases, the if statement
removed by this commit is not needed. In fact, removing it fix code as
shown in the test here added.

Fix google#1225
  • Loading branch information
rjodinchr authored Oct 24, 2023
1 parent 0f43a2a commit 3938c1d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/SimplifyPointerBitcastPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,9 @@ bool clspv::SimplifyPointerBitcastPass::runOnImplicitGEP(Module &M) const {
auto *gep = dyn_cast<GetElementPtrInst>(&I);
auto *call = dyn_cast_or_null<CallInst>(&I);
bool userCall = call && !call->getCalledFunction()->isDeclaration();
if ((Steps > 0 && !gep) || (Steps == 1)) {
if (!userCall && (gep || PerfectMatch)) {
GEPAliasingList.push_back(
{&I, Steps, PerfectMatch ? nullptr : gep});
}
if (!userCall && (gep || PerfectMatch)) {
GEPAliasingList.push_back(
{&I, Steps, PerfectMatch ? nullptr : gep});
}
} else if (isa<StoreInst>(&I) && !isa<GetElementPtrInst>(source)) {
GEPBeforeStoreList.push_back({&I, dest_ty});
Expand Down
18 changes: 18 additions & 0 deletions test/PointerCasts/issue-1225.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
; RUN: clspv-opt %s -o %t.ll --passes=simplify-pointer-bitcast,replace-pointer-bitcast
; RUN: FileCheck %s < %t.ll

; CHECK: [[gep:%[^ ]+]] = getelementptr { %struct.s, %struct.s }, ptr %alloca, i32 0, i32 0, i32 0, i32 1
; CHECK: load i64, ptr [[gep]], align 8

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-unknown"

%struct.s = type { [8 x i64], i32 }

define spir_kernel void @foo() {
entry:
%alloca = alloca { %struct.s, %struct.s }, align 8
%gep = getelementptr inbounds [8 x i64], ptr %alloca, i64 0, i64 1
%load = load i64, ptr %gep, align 8
ret void
}

0 comments on commit 3938c1d

Please sign in to comment.