From 3938c1d86391493a25f31b5ec3693880da988096 Mon Sep 17 00:00:00 2001 From: Romaric Jodin <89833130+rjodinchr@users.noreply.github.com> Date: Tue, 24 Oct 2023 14:30:40 +0200 Subject: [PATCH] fix runOnImplicitGEP for more than 1 index missing (#1254) 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 #1225 --- lib/SimplifyPointerBitcastPass.cpp | 8 +++----- test/PointerCasts/issue-1225.ll | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 test/PointerCasts/issue-1225.ll diff --git a/lib/SimplifyPointerBitcastPass.cpp b/lib/SimplifyPointerBitcastPass.cpp index 3128b11a8..e8522c6dc 100644 --- a/lib/SimplifyPointerBitcastPass.cpp +++ b/lib/SimplifyPointerBitcastPass.cpp @@ -460,11 +460,9 @@ bool clspv::SimplifyPointerBitcastPass::runOnImplicitGEP(Module &M) const { auto *gep = dyn_cast(&I); auto *call = dyn_cast_or_null(&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(&I) && !isa(source)) { GEPBeforeStoreList.push_back({&I, dest_ty}); diff --git a/test/PointerCasts/issue-1225.ll b/test/PointerCasts/issue-1225.ll new file mode 100644 index 000000000..2a90a6432 --- /dev/null +++ b/test/PointerCasts/issue-1225.ll @@ -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 +}