https://github.com/adams381 updated 
https://github.com/llvm/llvm-project/pull/242404

>From 66ada7f8fcb130f3370f1ce3cac8d56286a78a46 Mon Sep 17 00:00:00 2001
From: Adam Smith <[email protected]>
Date: Fri, 13 Nov 2026 08:54:23 -0800
Subject: [PATCH 1/2] [CIR] Lower get_element's leading zero with the index's
 type

The GEP that cir.get_element lowers to starts with a zero index.  It was
a raw constant, which MLIR's translation always emits as i32, so CIR
produced `getelementptr [N x T], ptr %p, i32 0, i64 %i` where classic
codegen produces `i64 0, i64 %i`.  The zero is now a constant of the
index operand's type, so the two match on x86_64 and on AMDGPU for flat,
global and constant pointers.

In AMDGPU's 32-bit private and local address spaces, the lowering
truncates the index to i32 before the GEP, so both indices are i32 there
while classic codegen keeps them i64.

Assisted-by: Cursor / Claude Opus 5.5
---
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 11 ++-
 .../CIR/CodeGen/amdgpu-array-addrspace.cpp    |  2 +-
 .../CIR/CodeGen/array-init-loop-exprs.cpp     |  8 +-
 .../CIR/CodeGen/array-subscript-inbounds.c    | 82 +++++--------------
 clang/test/CIR/CodeGen/array.cpp              | 16 ++--
 clang/test/CIR/CodeGen/binassign.c            |  2 +-
 clang/test/CIR/CodeGen/bitint-wide.c          |  8 +-
 clang/test/CIR/CodeGen/complex.cpp            |  2 +-
 clang/test/CIR/CodeGen/no-odr-use.cpp         | 12 +--
 clang/test/CIR/CodeGen/union.c                |  4 +-
 .../CodeGenOpenCL/amdgpu-array-subscript.cl   | 39 +++++++++
 .../CodeGenOpenMP/device-array-subscript.c    | 36 ++++----
 clang/test/CIR/Lowering/array.cpp             |  8 +-
 clang/test/CIR/Lowering/get-element.cir       | 18 +++-
 14 files changed, 127 insertions(+), 121 deletions(-)
 create mode 100644 clang/test/CIR/CodeGenOpenCL/amdgpu-array-subscript.cl

diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp 
b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index 4ceb933698dfff..c0afff41a55332 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -2305,10 +2305,13 @@ mlir::LogicalResult 
CIRToLLVMGetElementOpLowering::matchAndRewrite(
                          adaptor.getBase().getType(),
                          dyn_cast<cir::IntType>(op.getOperand(1).getType()));
 
-    // Since the base address is a pointer to an aggregate, the first
-    // offset is always zero. The second offset tell us which member it
-    // will access.
-    std::array<mlir::LLVM::GEPArg, 2> offset{0, index};
+    // Since the base address is a pointer to an array, the first index is
+    // always zero, and the second one selects the element.  The zero takes the
+    // element index's type, because a raw constant GEP index is always
+    // translated as i32.
+    mlir::Value zero = mlir::LLVM::ConstantOp::create(rewriter, op.getLoc(),
+                                                      index.getType(), 0);
+    std::array<mlir::LLVM::GEPArg, 2> offset = {zero, index};
     mlir::LLVM::GEPNoWrapFlags flags = mlir::LLVM::GEPNoWrapFlags::none;
     if (op.getInBounds())
       flags |= mlir::LLVM::GEPNoWrapFlags::inbounds;
diff --git a/clang/test/CIR/CodeGen/amdgpu-array-addrspace.cpp 
b/clang/test/CIR/CodeGen/amdgpu-array-addrspace.cpp
index 080d3ba1e24966..c9a82d01b08804 100644
--- a/clang/test/CIR/CodeGen/amdgpu-array-addrspace.cpp
+++ b/clang/test/CIR/CodeGen/amdgpu-array-addrspace.cpp
@@ -53,7 +53,7 @@ void pass_global_array() {
 // CIR-NEXT:    %{{.*}} = cir.load align(4) %[[ELEM]] : !cir.ptr<!s32i>, !s32i
 
 // LLVM-LABEL: define{{.*}} i32 @_Z18index_global_arrayi
-// LLVM:         %[[GEP:.*]] = getelementptr inbounds [10 x i32], ptr 
addrspacecast (ptr addrspace(1) @globalArr to ptr), i32 0, i64 %{{.*}}
+// LLVM:         %[[GEP:.*]] = getelementptr inbounds [10 x i32], ptr 
addrspacecast (ptr addrspace(1) @globalArr to ptr), i64 0, i64 %{{.*}}
 // LLVM-NEXT:    %{{.*}} = load i32, ptr %[[GEP]], align 4
 
 // OGCG-LABEL: define{{.*}} i32 @_Z18index_global_arrayi
diff --git a/clang/test/CIR/CodeGen/array-init-loop-exprs.cpp 
b/clang/test/CIR/CodeGen/array-init-loop-exprs.cpp
index 109cedb027731a..1922b76d80d4c7 100644
--- a/clang/test/CIR/CodeGen/array-init-loop-exprs.cpp
+++ b/clang/test/CIR/CodeGen/array-init-loop-exprs.cpp
@@ -175,7 +175,7 @@ struct HasMultiDimArray {
 // LLVM: %[[START_PTR:.*]] = ptrtoint ptr %[[THIS_ARR_DECAY]] to i64
 // LLVM: %[[PTR_DIFF:.*]] = sub i64 %[[ITR_PTR]], %[[START_PTR]]
 // LLVM: %[[IDX:.*]] = sdiv exact i64 %[[PTR_DIFF]], 4
-// LLVM: %[[RHS_ELT:.*]] = getelementptr inbounds nuw [3 x 
%struct.NonTrivial], ptr %[[RHS_ARR]], i32 0, i64 %[[IDX]]
+// LLVM: %[[RHS_ELT:.*]] = getelementptr inbounds nuw [3 x 
%struct.NonTrivial], ptr %[[RHS_ARR]], i64 0, i64 %[[IDX]]
 // LLVM: call void @_ZN10NonTrivialC1ERKS_(ptr {{.*}}%[[LOAD_ITR]], ptr 
{{.*}}%[[RHS_ELT]])
 // LLVM: %[[NEXT_ITR:.*]] = getelementptr %struct.NonTrivial, ptr 
%[[LOAD_ITR]], i64 1
 // LLVM: store ptr %[[NEXT_ITR]], ptr %[[ITR_ALLOCA]]
@@ -210,7 +210,7 @@ struct HasMultiDimArray {
 // LLVM: %[[ITR1_START_PTR:.*]] = ptrtoint ptr %[[THIS_ARR_DECAY]] to i64
 // LLVM: %[[PTR_DIFF:.*]] = sub i64 %[[ITR1_PTR]], %[[ITR1_START_PTR]]
 // LLVM: %[[IDX1:.*]] = sdiv exact i64 %[[PTR_DIFF]], 48
-// LLVM: %[[RHS_ELT1:.*]] = getelementptr inbounds nuw [2 x [3 x [4 x 
%struct.NonTrivial]]], ptr %[[RHS_ARR]], i32 0, i64 %[[IDX1]]
+// LLVM: %[[RHS_ELT1:.*]] = getelementptr inbounds nuw [2 x [3 x [4 x 
%struct.NonTrivial]]], ptr %[[RHS_ARR]], i64 0, i64 %[[IDX1]]
 // LLVM: %[[ARR1_DECAY:.*]] = getelementptr [4 x %struct.NonTrivial], ptr 
%[[ITR1_LOAD]], i32 0
 // LLVM: store ptr %[[ARR1_DECAY]], ptr %[[ITR2_ALLOCA]]
 // LLVM: %[[END_ITR2:.*]] = getelementptr [4 x %struct.NonTrivial], ptr 
%[[ARR1_DECAY]], i64 3
@@ -227,7 +227,7 @@ struct HasMultiDimArray {
 // LLVM: %[[ITR2_START_PTR:.*]] = ptrtoint ptr %[[ARR1_DECAY]] to i64
 // LLVM: %[[PTR_DIFF:.*]] = sub i64 %[[ITR2_PTR]], %[[ITR2_START_PTR]]
 // LLVM: %[[IDX2:.*]] = sdiv exact i64 %[[PTR_DIFF]], 16
-// LLVM: %[[RHS_ELT2:.*]] = getelementptr inbounds nuw [3 x [4 x 
%struct.NonTrivial]], ptr %[[RHS_ELT1]], i32 0, i64 %[[IDX2]]
+// LLVM: %[[RHS_ELT2:.*]] = getelementptr inbounds nuw [3 x [4 x 
%struct.NonTrivial]], ptr %[[RHS_ELT1]], i64 0, i64 %[[IDX2]]
 // LLVM: %[[ARR2_DECAY:.*]] = getelementptr %struct.NonTrivial, ptr 
%[[ITR2_LOAD]], i32 0
 // LLVM: store ptr %[[ARR2_DECAY]], ptr %[[ITR3_ALLOCA]]
 // LLVM: %[[END_ITR3:.*]] = getelementptr %struct.NonTrivial, ptr 
%[[ARR2_DECAY]], i64 4
@@ -244,7 +244,7 @@ struct HasMultiDimArray {
 // LLVM: %[[ITR3_START_PTR:.*]] = ptrtoint ptr %[[ARR2_DECAY]] to i64
 // LLVM: %[[PTR_DIFF:.*]] = sub i64 %[[ITR3_PTR]], %[[ITR3_START_PTR]]
 // LLVM: %[[IDX3:.*]] = sdiv exact i64 %[[PTR_DIFF]], 4
-// LLVM: %[[RHS_ELT3:.*]] = getelementptr inbounds nuw [4 x 
%struct.NonTrivial], ptr %[[RHS_ELT2]], i32 0, i64 %[[IDX3]]
+// LLVM: %[[RHS_ELT3:.*]] = getelementptr inbounds nuw [4 x 
%struct.NonTrivial], ptr %[[RHS_ELT2]], i64 0, i64 %[[IDX3]]
 // LLVM: call void @_ZN10NonTrivialC1ERKS_(ptr{{.*}} %[[ITR3_LOAD]], ptr{{.*}} 
%[[RHS_ELT3]])
 // LLVM: %[[NEXT_ITR3:.*]] = getelementptr %struct.NonTrivial, ptr 
%[[ITR3_LOAD]], i64 1
 // LLVM: store ptr %[[NEXT_ITR3]], ptr %[[ITR3_ALLOCA]]
diff --git a/clang/test/CIR/CodeGen/array-subscript-inbounds.c 
b/clang/test/CIR/CodeGen/array-subscript-inbounds.c
index c3f634c4a71916..cbe64c167740e2 100644
--- a/clang/test/CIR/CodeGen/array-subscript-inbounds.c
+++ b/clang/test/CIR/CodeGen/array-subscript-inbounds.c
@@ -1,15 +1,15 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o 
%t.cir
 // RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o 
%t-cir.ll
-// RUN: FileCheck --check-prefixes=LLVM,LLVMCIR --input-file=%t-cir.ll %s
+// RUN: FileCheck --check-prefix=LLVM --input-file=%t-cir.ll %s
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
-// RUN: FileCheck --check-prefixes=LLVM,OGCG --input-file=%t.ll %s
+// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fwrapv-pointer -fclangir 
-emit-cir %s -o %t-wrapv.cir
 // RUN: FileCheck --check-prefix=WRAPV-CIR --input-file=%t-wrapv.cir %s
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fwrapv-pointer -fclangir 
-emit-llvm %s -o %t-wrapv-cir.ll
-// RUN: FileCheck --check-prefixes=WRAPV-LLVM,WRAPV-LLVMCIR 
--input-file=%t-wrapv-cir.ll %s
+// RUN: FileCheck --check-prefix=WRAPV-LLVM --input-file=%t-wrapv-cir.ll %s
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fwrapv-pointer -emit-llvm 
%s -o %t-wrapv.ll
-// RUN: FileCheck --check-prefixes=WRAPV-LLVM,WRAPV-OGCG 
--input-file=%t-wrapv.ll %s
+// RUN: FileCheck --check-prefix=WRAPV-LLVM --input-file=%t-wrapv.ll %s
 
 int signed_index(int i) {
   int a[4] = {0};
@@ -24,10 +24,7 @@ int signed_index(int i) {
 // LLVM-LABEL: define dso_local i32 @signed_index(
 // LLVM:         %[[A:.*]] = alloca [4 x i32], align 16
 // LLVM:         %[[IDX:.*]] = sext i32 %{{.*}} to i64
-// LLVM:         getelementptr inbounds [4 x i32], ptr %[[A]],
-// LLVMCIR-SAME:   i32 0,
-// OGCG-SAME:      i64 0,
-// LLVM-SAME:      i64 %[[IDX]]
+// LLVM:         getelementptr inbounds [4 x i32], ptr %[[A]], i64 0, i64 
%[[IDX]]
 
 // WRAPV-CIR-LABEL: cir.func {{.*}} @signed_index(
 // WRAPV-CIR:         cir.get_element %{{.*}}[%{{.*}} : !s64i] : 
!cir.ptr<!cir.array<!s32i x 4>> -> !cir.ptr<!s32i>
@@ -35,10 +32,7 @@ int signed_index(int i) {
 // WRAPV-LLVM-LABEL: define dso_local i32 @signed_index(
 // WRAPV-LLVM:         %[[A:.*]] = alloca [4 x i32], align 16
 // WRAPV-LLVM:         %[[IDX:.*]] = sext i32 %{{.*}} to i64
-// WRAPV-LLVM:         getelementptr [4 x i32], ptr %[[A]],
-// WRAPV-LLVMCIR-SAME:   i32 0,
-// WRAPV-OGCG-SAME:      i64 0,
-// WRAPV-LLVM-SAME:      i64 %[[IDX]]
+// WRAPV-LLVM:         getelementptr [4 x i32], ptr %[[A]], i64 0, i64 %[[IDX]]
 
 int unsigned_index(unsigned u) {
   int a[4] = {0};
@@ -53,10 +47,7 @@ int unsigned_index(unsigned u) {
 // LLVM-LABEL: define dso_local i32 @unsigned_index(
 // LLVM:         %[[A:.*]] = alloca [4 x i32], align 16
 // LLVM:         %[[IDX:.*]] = zext i32 %{{.*}} to i64
-// LLVM:         getelementptr inbounds nuw [4 x i32], ptr %[[A]],
-// LLVMCIR-SAME:   i32 0,
-// OGCG-SAME:      i64 0,
-// LLVM-SAME:      i64 %[[IDX]]
+// LLVM:         getelementptr inbounds nuw [4 x i32], ptr %[[A]], i64 0, i64 
%[[IDX]]
 
 // WRAPV-CIR-LABEL: cir.func {{.*}} @unsigned_index(
 // WRAPV-CIR:         cir.get_element %{{.*}}[%{{.*}} : !u64i] : 
!cir.ptr<!cir.array<!s32i x 4>> -> !cir.ptr<!s32i>
@@ -64,10 +55,7 @@ int unsigned_index(unsigned u) {
 // WRAPV-LLVM-LABEL: define dso_local i32 @unsigned_index(
 // WRAPV-LLVM:         %[[A:.*]] = alloca [4 x i32], align 16
 // WRAPV-LLVM:         %[[IDX:.*]] = zext i32 %{{.*}} to i64
-// WRAPV-LLVM:         getelementptr [4 x i32], ptr %[[A]],
-// WRAPV-LLVMCIR-SAME:   i32 0,
-// WRAPV-OGCG-SAME:      i64 0,
-// WRAPV-LLVM-SAME:      i64 %[[IDX]]
+// WRAPV-LLVM:         getelementptr [4 x i32], ptr %[[A]], i64 0, i64 %[[IDX]]
 
 int constant_index(void) {
   int a[4] = {0};
@@ -81,10 +69,7 @@ int constant_index(void) {
 
 // LLVM-LABEL: define dso_local i32 @constant_index(
 // LLVM:         %[[A:.*]] = alloca [4 x i32], align 16
-// LLVM:         getelementptr inbounds [4 x i32], ptr %[[A]],
-// LLVMCIR-SAME:   i32 0,
-// OGCG-SAME:      i64 0,
-// LLVM-SAME:      i64 1
+// LLVM:         getelementptr inbounds [4 x i32], ptr %[[A]], i64 0, i64 1
 
 int unsigned_constant_index(void) {
   int a[4] = {0};
@@ -98,10 +83,7 @@ int unsigned_constant_index(void) {
 
 // LLVM-LABEL: define dso_local i32 @unsigned_constant_index(
 // LLVM:         %[[A:.*]] = alloca [4 x i32], align 16
-// LLVM:         getelementptr inbounds nuw [4 x i32], ptr %[[A]],
-// LLVMCIR-SAME:   i32 0,
-// OGCG-SAME:      i64 0,
-// LLVM-SAME:      i64 1
+// LLVM:         getelementptr inbounds nuw [4 x i32], ptr %[[A]], i64 0, i64 1
 
 enum SignedIdx { NegOne = -1, SZero, SOne };
 enum UnsignedIdx { UZero, UOne };
@@ -121,15 +103,9 @@ int enum_index(enum SignedIdx s, enum UnsignedIdx u) {
 // LLVM-LABEL: define dso_local i32 @enum_index(
 // LLVM:         %[[A:.*]] = alloca [4 x i32], align 16
 // LLVM:         %[[S:.*]] = sext i32 %{{.*}} to i64
-// LLVM:         getelementptr inbounds [4 x i32], ptr %[[A]],
-// LLVMCIR-SAME:   i32 0,
-// OGCG-SAME:      i64 0,
-// LLVM-SAME:      i64 %[[S]]
+// LLVM:         getelementptr inbounds [4 x i32], ptr %[[A]], i64 0, i64 
%[[S]]
 // LLVM:         %[[U:.*]] = zext i32 %{{.*}} to i64
-// LLVM:         getelementptr inbounds nuw [4 x i32], ptr %[[A]],
-// LLVMCIR-SAME:   i32 0,
-// OGCG-SAME:      i64 0,
-// LLVM-SAME:      i64 %[[U]]
+// LLVM:         getelementptr inbounds nuw [4 x i32], ptr %[[A]], i64 0, i64 
%[[U]]
 
 int reversed_subscript(int i, unsigned u) {
   int a[4] = {0};
@@ -146,15 +122,9 @@ int reversed_subscript(int i, unsigned u) {
 // LLVM-LABEL: define dso_local i32 @reversed_subscript(
 // LLVM:         %[[A:.*]] = alloca [4 x i32], align 16
 // LLVM:         %[[I:.*]] = sext i32 %{{.*}} to i64
-// LLVM:         getelementptr inbounds [4 x i32], ptr %[[A]],
-// LLVMCIR-SAME:   i32 0,
-// OGCG-SAME:      i64 0,
-// LLVM-SAME:      i64 %[[I]]
+// LLVM:         getelementptr inbounds [4 x i32], ptr %[[A]], i64 0, i64 
%[[I]]
 // LLVM:         %[[U:.*]] = zext i32 %{{.*}} to i64
-// LLVM:         getelementptr inbounds nuw [4 x i32], ptr %[[A]],
-// LLVMCIR-SAME:   i32 0,
-// OGCG-SAME:      i64 0,
-// LLVM-SAME:      i64 %[[U]]
+// LLVM:         getelementptr inbounds nuw [4 x i32], ptr %[[A]], i64 0, i64 
%[[U]]
 
 int two_dimensions(int i, unsigned j) {
   int a[3][4] = {{0}};
@@ -171,15 +141,9 @@ int two_dimensions(int i, unsigned j) {
 // LLVM-LABEL: define dso_local i32 @two_dimensions(
 // LLVM:         %[[A:.*]] = alloca [3 x [4 x i32]], align 16
 // LLVM:         %[[I:.*]] = sext i32 %{{.*}} to i64
-// LLVM:         %[[ROW:.*]] = getelementptr inbounds [3 x [4 x i32]], ptr 
%[[A]],
-// LLVMCIR-SAME:   i32 0,
-// OGCG-SAME:      i64 0,
-// LLVM-SAME:      i64 %[[I]]
+// LLVM:         %[[ROW:.*]] = getelementptr inbounds [3 x [4 x i32]], ptr 
%[[A]], i64 0, i64 %[[I]]
 // LLVM:         %[[J:.*]] = zext i32 %{{.*}} to i64
-// LLVM:         getelementptr inbounds nuw [4 x i32], ptr %[[ROW]],
-// LLVMCIR-SAME:   i32 0,
-// OGCG-SAME:      i64 0,
-// LLVM-SAME:      i64 %[[J]]
+// LLVM:         getelementptr inbounds nuw [4 x i32], ptr %[[ROW]], i64 0, 
i64 %[[J]]
 
 int pointer_to_2d(int (*p)[3][4], int i, int j) { return (*p)[i][j]; }
 
@@ -188,8 +152,8 @@ int pointer_to_2d(int (*p)[3][4], int i, int j) { return 
(*p)[i][j]; }
 // CIR:         cir.get_element inbounds %[[ROW]][%{{.*}} : !s64i] : 
!cir.ptr<!cir.array<!s32i x 4>> -> !cir.ptr<!s32i>
 
 // LLVM-LABEL: define dso_local i32 @pointer_to_2d(
-// LLVM:         %[[ROW:.*]] = getelementptr inbounds [3 x [4 x i32]], ptr
-// LLVM:         getelementptr inbounds [4 x i32], ptr %[[ROW]],
+// LLVM:         %[[ROW:.*]] = getelementptr inbounds [3 x [4 x i32]], ptr 
%{{.*}}, i64 0, i64 %{{.*}}
+// LLVM:         getelementptr inbounds [4 x i32], ptr %[[ROW]], i64 0, i64 
%{{.*}}
 
 struct Flex {
   int n;
@@ -206,10 +170,7 @@ int flexible_member(struct Flex *s, int i) { return 
s->a[i]; }
 // LLVM-LABEL: define dso_local i32 @flexible_member(
 // LLVM:         %[[MEMBER:.*]] = getelementptr inbounds nuw %struct.Flex, ptr 
%{{.*}}, i32 0, i32 1
 // LLVM:         %[[IDX:.*]] = sext i32 %{{.*}} to i64
-// LLVM:         getelementptr inbounds [0 x i32], ptr %[[MEMBER]],
-// LLVMCIR-SAME:   i32 0,
-// OGCG-SAME:      i64 0,
-// LLVM-SAME:      i64 %[[IDX]]
+// LLVM:         getelementptr inbounds [0 x i32], ptr %[[MEMBER]], i64 0, i64 
%[[IDX]]
 
 static const int debruijn[32] = {
     0,  1,  28, 2,  29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4,  8,
@@ -226,7 +187,4 @@ int count_trailing_zeros(unsigned x) {
 
 // LLVM-LABEL: define dso_local i32 @count_trailing_zeros(
 // LLVM:         %[[IDX:.*]] = zext i32 %{{.*}} to i64
-// LLVM:         getelementptr inbounds nuw [32 x i32], ptr @debruijn,
-// LLVMCIR-SAME:   i32 0,
-// OGCG-SAME:      i64 0,
-// LLVM-SAME:      i64 %[[IDX]]
+// LLVM:         getelementptr inbounds nuw [32 x i32], ptr @debruijn, i64 0, 
i64 %[[IDX]]
diff --git a/clang/test/CIR/CodeGen/array.cpp b/clang/test/CIR/CodeGen/array.cpp
index 2502c2cf093b1b..0e33e6e2effcda 100644
--- a/clang/test/CIR/CodeGen/array.cpp
+++ b/clang/test/CIR/CodeGen/array.cpp
@@ -181,10 +181,10 @@ void func() {
 // LLVM-NEXT: %[[ARR:.*]] = alloca [10 x i32], align 16
 // LLVM-NEXT: %[[INIT:.*]] = alloca i32, align 4
 // LLVM-NEXT: %[[INIT_2:.*]] = alloca i32, align 4
-// LLVM-NEXT: %[[ELE_PTR:.*]] = getelementptr inbounds [10 x i32], ptr 
%[[ARR]], i32 0, i64 0
+// LLVM-NEXT: %[[ELE_PTR:.*]] = getelementptr inbounds [10 x i32], ptr 
%[[ARR]], i64 0, i64 0
 // LLVM-NEXT: %[[TMP_1:.*]] = load i32, ptr %[[ELE_PTR]], align 16
 // LLVM-NEXT: store i32 %[[TMP_1]], ptr %[[INIT]], align 4
-// LLVM-NEXT: %[[ELE_PTR:.*]] = getelementptr inbounds [10 x i32], ptr 
%[[ARR]], i32 0, i64 1
+// LLVM-NEXT: %[[ELE_PTR:.*]] = getelementptr inbounds [10 x i32], ptr 
%[[ARR]], i64 0, i64 1
 // LLVM-NEXT: %[[TMP_2:.*]] = load i32, ptr %[[ELE_PTR]], align 4
 // LLVM-NEXT: store i32 %[[TMP_2]], ptr %[[INIT_2]], align 4
 
@@ -241,7 +241,7 @@ void func3() {
 // LLVM:  store i32 1, ptr %[[IDX]], align 4
 // LLVM:  %[[TMP1:.*]] = load i32, ptr %[[IDX]], align 4
 // LLVM:  %[[IDX_I64:.*]] = sext i32 %[[TMP1]] to i64
-// LLVM:  %[[ELE:.*]] = getelementptr inbounds [2 x i32], ptr %[[ARR]], i32 0, 
i64 %[[IDX_I64]]
+// LLVM:  %[[ELE:.*]] = getelementptr inbounds [2 x i32], ptr %[[ARR]], i64 0, 
i64 %[[IDX_I64]]
 // LLVM:  %[[TMP2:.*]] = load i32, ptr %[[ELE]], align 4
 // LLVM:  store i32 %[[TMP2]], ptr %[[INIT]], align 4
 
@@ -276,8 +276,8 @@ void func4() {
 // LLVM:  %[[ARR:.*]] = alloca [2 x [1 x i32]], align 4
 // LLVM:  %[[INIT:.*]] = alloca i32, align 4
 // LLVM:  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[ARR]], ptr align 4 
@[[FUNC4_ARR:.*]], i64 8, i1 false)
-// LLVM:  %[[ARR_1:.*]] = getelementptr inbounds [2 x [1 x i32]], ptr 
%[[ARR]], i32 0, i64 1
-// LLVM:  %[[ELE_PTR:.*]] = getelementptr inbounds [1 x i32], ptr %[[ARR_1]], 
i32 0, i64 0
+// LLVM:  %[[ARR_1:.*]] = getelementptr inbounds [2 x [1 x i32]], ptr 
%[[ARR]], i64 0, i64 1
+// LLVM:  %[[ELE_PTR:.*]] = getelementptr inbounds [1 x i32], ptr %[[ARR_1]], 
i64 0, i64 0
 // LLVM:  %[[TMP:.*]] = load i32, ptr %[[ELE_PTR]], align 4
 // LLVM:  store i32 %[[TMP]], ptr %[[INIT]], align 4
 
@@ -424,7 +424,7 @@ void func9(int arr[10][5]) {
 // LLVM:  store ptr %[[ARG]], ptr %[[ARR]], align 8
 // LLVM:  %[[TMP_1:.*]] = load ptr, ptr %[[ARR]], align 8
 // LLVM:  %[[ARR_1:.*]] = getelementptr [5 x i32], ptr %[[TMP_1]], i64 1
-// LLVM:  %[[ARR_1_2:.*]] = getelementptr inbounds [5 x i32], ptr %[[ARR_1]], 
i32 0, i64 2
+// LLVM:  %[[ARR_1_2:.*]] = getelementptr inbounds [5 x i32], ptr %[[ARR_1]], 
i64 0, i64 2
 // LLVM:  %[[TMP_2:.*]] = load i32, ptr %[[ARR_1_2]], align 4
 // LLVM:  store i32 %[[TMP_2]], ptr %[[INIT]], align 4
 
@@ -527,7 +527,7 @@ void boolean_index_access(int x) {
 // LLVM: %[[X:.*]] = load i32, ptr %[[X_ADDR]]
 // LLVM: %[[CMP:.*]] = icmp sgt i32 %[[X]], 4
 // LLVM: %[[IDX:.*]] = zext i1 %[[CMP]] to i64
-// LLVM: %[[ELE:.*]] = getelementptr inbounds nuw [2 x i32], ptr 
%[[ARR_ADDR]], i32 0, i64 %[[IDX]]
+// LLVM: %[[ELE:.*]] = getelementptr inbounds nuw [2 x i32], ptr 
%[[ARR_ADDR]], i64 0, i64 %[[IDX]]
 // LLVM: %[[VAL:.*]] = load i32, ptr %[[ELE]]
 // LLVM: store i32 %[[VAL]], ptr %[[N_ADDR]]
 
@@ -566,7 +566,7 @@ void bitint_index_access(_BitInt(7) i) {
 // LLVM:   %[[I:.*]] = load i8, ptr %[[I_ADDR]]
 // LLVM:   %[[I_CAST:.*]] = trunc i8 %[[I]] to i7
 // LLVM:   %[[IDX:.*]] = sext i7 %[[I_CAST]] to i64
-// LLVM:   %[[ELE:.*]] = getelementptr inbounds [10 x i32], ptr %[[ARR_ADDR]], 
i32 0, i64 %[[IDX]]
+// LLVM:   %[[ELE:.*]] = getelementptr inbounds [10 x i32], ptr %[[ARR_ADDR]], 
i64 0, i64 %[[IDX]]
 // LLVM:   %[[VAL:.*]] = load i32, ptr %[[ELE]]
 // LLVM:   store i32 %[[VAL]], ptr %[[N_ADDR]]
 
diff --git a/clang/test/CIR/CodeGen/binassign.c 
b/clang/test/CIR/CodeGen/binassign.c
index b7a6d09ce0808d..fdf2598f0b9fed 100644
--- a/clang/test/CIR/CodeGen/binassign.c
+++ b/clang/test/CIR/CodeGen/binassign.c
@@ -155,7 +155,7 @@ int ignore_result_assign() {
 // LLVM:         store i32 123, ptr %[[I_PTR]]
 // LLVM:         store i32 123, ptr %[[J_PTR]]
 // LLVM:         store i32 5, ptr %[[I_PTR]]
-// LLVM:         %[[GEP:.*]] = getelementptr inbounds [10 x i32], ptr 
%[[ARR_PTR]], i32 0, i64 5
+// LLVM:         %[[GEP:.*]] = getelementptr inbounds [10 x i32], ptr 
%[[ARR_PTR]], i64 0, i64 5
 // LLVM:         %[[ARR_VAL:.*]] = load i32, ptr %[[GEP]]
 // LLVM:         store i32 %[[ARR_VAL]], ptr %[[J_PTR]]
 // LLVM:         store ptr null, ptr %[[Q_PTR]]
diff --git a/clang/test/CIR/CodeGen/bitint-wide.c 
b/clang/test/CIR/CodeGen/bitint-wide.c
index 6b843845fc05d2..17b3fb53994bbe 100644
--- a/clang/test/CIR/CodeGen/bitint-wide.c
+++ b/clang/test/CIR/CodeGen/bitint-wide.c
@@ -100,13 +100,9 @@ _BitInt(129) local_arr(void) {
 // LLVM-SAME: ptr{{.*}}%[[RET_ARG:.*]])
 // LLVM: %[[ARR:.*]] = alloca [2 x [24 x i8]], align 16
 // LLVM: call void @llvm.memcpy.p0.p0.i64(ptr align 16 %[[ARR]], ptr align 16 
@__const.local_arr.arr, i64 48, i1 false)
-// LLVM: %[[GET_ELT_ONE:.*]] = getelementptr inbounds [2 x [24 x i8]], ptr 
%[[ARR]],
-// CIRONLY-SAME: i32 0, i64 1
-// OGCG-SAME: i64 0, i64 1
+// LLVM: %[[GET_ELT_ONE:.*]] = getelementptr inbounds [2 x [24 x i8]], ptr 
%[[ARR]], i64 0, i64 1
 // LLVM: store i192 3, ptr %[[GET_ELT_ONE]], align 8
-// LLVM: %[[GET_ELT_ZERO:.*]] = getelementptr inbounds [2 x [24 x i8]], ptr 
%[[ARR]],
-// CIRONLY-SAME: i32 0, i64 0
-// OGCG-SAME: i64 0, i64 0
+// LLVM: %[[GET_ELT_ZERO:.*]] = getelementptr inbounds [2 x [24 x i8]], ptr 
%[[ARR]], i64 0, i64 0
 // LLVM: %[[LOAD_ELT_ZERO:.*]] = load i192, ptr %[[GET_ELT_ZERO]], align 16
 // LLVM: %[[TRUNC_ELT:.*]] = trunc i192 %[[LOAD_ELT_ZERO]] to i129
 // LLVM: %[[EXT_ELT:.*]] = sext i129 %[[TRUNC_ELT]] to i192
diff --git a/clang/test/CIR/CodeGen/complex.cpp 
b/clang/test/CIR/CodeGen/complex.cpp
index 407a6a8b0e6ea9..d2abd551c2063f 100644
--- a/clang/test/CIR/CodeGen/complex.cpp
+++ b/clang/test/CIR/CodeGen/complex.cpp
@@ -686,7 +686,7 @@ void foo24() {
 
 // LLVM: %[[ARR:.*]] = alloca [2 x { i32, i32 }], align 16
 // LLVM: %[[RESULT:.*]] = alloca { i32, i32 }, align 4
-// LLVM: %[[RESULT_VAL:.*]] = getelementptr inbounds [2 x { i32, i32 }], ptr 
%[[ARR]], i32 0, i64 1
+// LLVM: %[[RESULT_VAL:.*]] = getelementptr inbounds [2 x { i32, i32 }], ptr 
%[[ARR]], i64 0, i64 1
 // LLVM: %[[TMP:.*]] = load { i32, i32 }, ptr %[[RESULT_VAL]], align 8
 // LLVM: store { i32, i32 } %[[TMP]], ptr %[[RESULT]], align 4
 
diff --git a/clang/test/CIR/CodeGen/no-odr-use.cpp 
b/clang/test/CIR/CodeGen/no-odr-use.cpp
index d9d9c5fe494351..c6d7a8e1646891 100644
--- a/clang/test/CIR/CodeGen/no-odr-use.cpp
+++ b/clang/test/CIR/CodeGen/no-odr-use.cpp
@@ -61,7 +61,7 @@ int f(int i) {
       // CIR:  %[[A:.*]] = cir.get_global @[[F_A]] : !cir.ptr<!rec_A>
       // CIR:  %[[ARR:.*]] = cir.get_member %[[A]][2] {name = "arr"} : 
!cir.ptr<!rec_A> -> !cir.ptr<!cir.array<!s32i x 3>>
       // CIR:  cir.get_element inbounds %[[ARR]][%{{.*}} : !s64i] : 
!cir.ptr<!cir.array<!s32i x 3>> -> !cir.ptr<!s32i>
-      // LLVM: getelementptr inbounds [3 x i32], ptr getelementptr inbounds 
nuw (i8, ptr @[[F_A]], i64 12), i32 0, i64 %{{.*}}
+      // LLVM: getelementptr inbounds [3 x i32], ptr getelementptr inbounds 
nuw (i8, ptr @[[F_A]], i64 12), i64 0, i64 %{{.*}}
       // OGCG: getelementptr inbounds [3 x i32], ptr getelementptr inbounds 
nuw (i8, ptr @__const._Z1fi.a, i64 12), i64 0, i64 %{{.*}}
       ? a.arr[n]
       // CIR:  cir.ternary
@@ -87,7 +87,7 @@ int f(int i) {
         // CIR: %[[SUB_64:.*]] = cir.cast integral %[[SUB]] : !s32i -> !s64i
         // CIR: cir.get_element inbounds %[[Y]][%[[SUB_64]] : !s64i] : 
!cir.ptr<!cir.array<!s32i x 2>> -> !cir.ptr<!s32i>
 
-        // LLVM: getelementptr inbounds [2 x i32], ptr getelementptr inbounds 
nuw (i8, ptr @[[F_A]], i64 4), i32 0, i64 %{{.*}}
+        // LLVM: getelementptr inbounds [2 x i32], ptr getelementptr inbounds 
nuw (i8, ptr @[[F_A]], i64 4), i64 0, i64 %{{.*}}
         // LLVM: load i32
 
         // OGCG: getelementptr inbounds [2 x i32], ptr getelementptr inbounds 
nuw (i8, ptr @__const._Z1fi.a, i64 4), i64 0, i64 %{{.*}}
@@ -116,8 +116,8 @@ namespace PR42276 {
       // CIR-CXX2A: %[[M:.*]] = cir.get_global @_ZN7PR422765State1mE : 
!cir.ptr<!cir.array<!rec_anon_struct x 2>>
       // CIR: cir.get_element inbounds %[[M]][%{{.*}} : !s64i] : 
!cir.ptr<!cir.array<!rec_anon_struct x 2>> -> !cir.ptr<!rec_anon_struct>
 
-      // LLVM-CXX11: getelementptr inbounds [2 x { i64, i64 }], ptr 
@_ZN7PR422765State1mE.const, i32 0, i64 %{{.*}}
-      // LLVM-CXX2A: getelementptr inbounds [2 x { i64, i64 }], ptr 
@_ZN7PR422765State1mE, i32 0, i64 %{{.*}}
+      // LLVM-CXX11: getelementptr inbounds [2 x { i64, i64 }], ptr 
@_ZN7PR422765State1mE.const, i64 0, i64 %{{.*}}
+      // LLVM-CXX2A: getelementptr inbounds [2 x { i64, i64 }], ptr 
@_ZN7PR422765State1mE, i64 0, i64 %{{.*}}
       // OGCG-CXX11: getelementptr inbounds [2 x { i64, i64 }], ptr 
@_ZN7PR422765State1mE.const, i64 0, i64 %{{.*}}
       // OGCG-CXX2A: getelementptr inbounds [2 x { i64, i64 }], ptr 
@_ZN7PR422765State1mE, i64 0, i64 %{{.*}}
       (this->*m[i])();
@@ -127,8 +127,8 @@ namespace PR42276 {
       // CIR-CXX11: %[[DMS:.*]] = cir.get_global @_ZN7PR422765State3dmsE.const 
: !cir.ptr<!cir.array<!s64i x 2>>
       // CIR-CXX2A: %[[DMS:.*]] = cir.get_global @_ZN7PR422765State3dmsE : 
!cir.ptr<!cir.array<!s64i x 2>>
       // CIR: cir.get_element inbounds %[[DMS]][%{{.*}} : !s64i] : 
!cir.ptr<!cir.array<!s64i x 2>> -> !cir.ptr<!s64i>
-      // LLVM-CXX11: getelementptr inbounds [2 x i64], ptr 
@_ZN7PR422765State3dmsE.const, i32 0, i64 %{{.*}}
-      // LLVM-CXX2A: getelementptr inbounds [2 x i64], ptr 
@_ZN7PR422765State3dmsE, i32 0, i64 %{{.*}}
+      // LLVM-CXX11: getelementptr inbounds [2 x i64], ptr 
@_ZN7PR422765State3dmsE.const, i64 0, i64 %{{.*}}
+      // LLVM-CXX2A: getelementptr inbounds [2 x i64], ptr 
@_ZN7PR422765State3dmsE, i64 0, i64 %{{.*}}
       // OGCG-CXX11: getelementptr inbounds [2 x i64], ptr 
@_ZN7PR422765State3dmsE.const, i64 0, i64 %{{.*}}
       // OGCG-CXX2A: getelementptr inbounds [2 x i64], ptr 
@_ZN7PR422765State3dmsE, i64 0, i64 %{{.*}}
       sum += this->*dms[i];
diff --git a/clang/test/CIR/CodeGen/union.c b/clang/test/CIR/CodeGen/union.c
index 65937399a1e832..08252fcae3c345 100644
--- a/clang/test/CIR/CodeGen/union.c
+++ b/clang/test/CIR/CodeGen/union.c
@@ -192,7 +192,7 @@ void f3(union U3 u) {
 // LLVM-NEXT:   store i40 %[[ARG]], ptr %[[COERCE]], align 8
 // LLVM-NEXT:   %[[U:.*]] = alloca %union.U3, align 1
 // LLVM-NEXT:   call void @llvm.memcpy.p0.p0.i64(ptr align 1 %[[U]], ptr align 
8 %[[COERCE]], i64 5, i1 false)
-// LLVM-NEXT:   %[[ELEM_PTR:.*]] = getelementptr inbounds [5 x i8], ptr 
%[[U]], i32 0, i64 2
+// LLVM-NEXT:   %[[ELEM_PTR:.*]] = getelementptr inbounds [5 x i8], ptr 
%[[U]], i64 0, i64 2
 // LLVM-NEXT:   store i8 0, ptr %[[ELEM_PTR]], align 1
 // LLVM-NEXT:   ret void
 
@@ -226,7 +226,7 @@ void f5(union U4 u) {
 // LLVM-NEXT:   store i64 %[[ARG]], ptr %[[COERCE]], align 8
 // LLVM-NEXT:   %[[U:.*]] = alloca %union.U4, align 4
 // LLVM-NEXT:   call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[U]], ptr align 
8 %[[COERCE]], i64 8, i1 false)
-// LLVM-NEXT:   %[[ELEM_PTR:.*]] = getelementptr inbounds [5 x i8], ptr 
%[[U]], i32 0, i64 4
+// LLVM-NEXT:   %[[ELEM_PTR:.*]] = getelementptr inbounds [5 x i8], ptr 
%[[U]], i64 0, i64 4
 // LLVM-NEXT:   store i8 65, ptr %[[ELEM_PTR]], align 4
 // LLVM-NEXT:   ret void
 
diff --git a/clang/test/CIR/CodeGenOpenCL/amdgpu-array-subscript.cl 
b/clang/test/CIR/CodeGenOpenCL/amdgpu-array-subscript.cl
new file mode 100644
index 00000000000000..f25f5f757f5858
--- /dev/null
+++ b/clang/test/CIR/CodeGenOpenCL/amdgpu-array-subscript.cl
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -triple amdgpu-amd-amdhsa -cl-std=CL2.0 -O0 -fclangir 
-emit-cir %s -o %t.cir
+// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR
+// RUN: %clang_cc1 -triple amdgpu-amd-amdhsa -cl-std=CL2.0 -O0 -fclangir 
-emit-llvm %s -o %t-cir.ll
+// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefixes=LLVM,LLVMCIR
+// RUN: %clang_cc1 -triple amdgpu-amd-amdhsa -cl-std=CL2.0 -O0 -emit-llvm %s 
-o %t.ll
+// RUN: FileCheck --input-file=%t.ll %s --check-prefixes=LLVM,OGCG
+
+void private_array(int i) {
+  int a[4];
+  a[i] = 1;
+}
+
+// CIR-LABEL: cir.func {{.*}} @private_array(
+// CIR:         %[[A:.*]] = cir.alloca "a" {{.*}} : !cir.ptr<!cir.array<!s32i 
x 4>, target_address_space(5)>
+// CIR:         %[[IDX:.*]] = cir.cast integral %{{.+}} : !s32i -> !s64i
+// CIR-NEXT:    cir.get_element inbounds %[[A]][%[[IDX]] : !s64i] : 
!cir.ptr<!cir.array<!s32i x 4>, target_address_space(5)> -> !cir.ptr<!s32i, 
target_address_space(5)>
+
+// LLVM-LABEL: define {{.*}} void @private_array(i32 noundef %{{.+}})
+// LLVM:         %[[A:.*]] = alloca [4 x i32], align 4, addrspace(5)
+// LLVM:         %[[SEXT:.*]] = sext i32 %{{.+}} to i64
+// LLVMCIR-NEXT: %[[TRUNC:.*]] = trunc i64 %[[SEXT]] to i32
+// LLVMCIR-NEXT: getelementptr inbounds [4 x i32], ptr addrspace(5) %[[A]], 
i32 0, i32 %[[TRUNC]]
+// OGCG-NEXT:    getelementptr inbounds [4 x i32], ptr addrspace(5) %[[A]], 
i64 0, i64 %[[SEXT]]
+
+int local_array(local int (*p)[4], int i) {
+  return (*p)[i];
+}
+
+// CIR-LABEL: cir.func {{.*}} @local_array(
+// CIR:         %[[P:.*]] = cir.load {{.*}} : 
!cir.ptr<!cir.ptr<!cir.array<!s32i x 4>, target_address_space(3)>, 
target_address_space(5)>, !cir.ptr<!cir.array<!s32i x 4>, 
target_address_space(3)>
+// CIR:         %[[IDX:.*]] = cir.cast integral %{{.+}} : !s32i -> !s64i
+// CIR-NEXT:    cir.get_element inbounds %[[P]][%[[IDX]] : !s64i] : 
!cir.ptr<!cir.array<!s32i x 4>, target_address_space(3)> -> !cir.ptr<!s32i, 
target_address_space(3)>
+
+// LLVM-LABEL: define {{.*}} i32 @local_array(ptr addrspace(3) noundef 
%{{.+}}, i32 noundef %{{.+}})
+// LLVM:         %[[P:.*]] = load ptr addrspace(3), ptr addrspace(5) %{{.+}}, 
align 4
+// LLVM:         %[[SEXT:.*]] = sext i32 %{{.+}} to i64
+// LLVMCIR-NEXT: %[[TRUNC:.*]] = trunc i64 %[[SEXT]] to i32
+// LLVMCIR-NEXT: getelementptr inbounds [4 x i32], ptr addrspace(3) %[[P]], 
i32 0, i32 %[[TRUNC]]
+// OGCG-NEXT:    getelementptr inbounds [4 x i32], ptr addrspace(3) %[[P]], 
i64 0, i64 %[[SEXT]]
diff --git a/clang/test/CIR/CodeGenOpenMP/device-array-subscript.c 
b/clang/test/CIR/CodeGenOpenMP/device-array-subscript.c
index 8adcf70f321801..72aa2a973afa9b 100644
--- a/clang/test/CIR/CodeGenOpenMP/device-array-subscript.c
+++ b/clang/test/CIR/CodeGenOpenMP/device-array-subscript.c
@@ -17,8 +17,8 @@ double param2d(double (*p)[5][10], int i, int j) { return 
(*p)[i][j]; }
 // CIR:         cir.get_element inbounds %{{.*}}[%{{.*}} : !s64i] : 
!cir.ptr<!cir.array<!cir.double x 10>> -> !cir.ptr<!cir.double>
 
 // LLVM-LABEL: define hidden double @param2d(
-// LLVM:         %[[ROW:.*]] = getelementptr [5 x [10 x double]], ptr
-// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]],
+// LLVM:         %[[ROW:.*]] = getelementptr [5 x [10 x double]], ptr %{{.*}}, 
i64 0, i64 %{{.*}}
+// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]], i64 0, 
i64 %{{.*}}
 
 double uparam2d(double (*p)[5][10], unsigned i, int j) { return (*p)[i][j]; }
 
@@ -27,8 +27,8 @@ double uparam2d(double (*p)[5][10], unsigned i, int j) { 
return (*p)[i][j]; }
 // CIR:         cir.get_element inbounds %{{.*}}[%{{.*}} : !s64i] : 
!cir.ptr<!cir.array<!cir.double x 10>> -> !cir.ptr<!cir.double>
 
 // LLVM-LABEL: define hidden double @uparam2d(
-// LLVM:         %[[ROW:.*]] = getelementptr nuw [5 x [10 x double]], ptr
-// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]],
+// LLVM:         %[[ROW:.*]] = getelementptr nuw [5 x [10 x double]], ptr 
%{{.*}}, i64 0, i64 %{{.*}}
+// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]], i64 0, 
i64 %{{.*}}
 
 double param3d(double (*p)[2][5][10], int i, int j, int k) {
   return (*p)[i][j][k];
@@ -40,9 +40,9 @@ double param3d(double (*p)[2][5][10], int i, int j, int k) {
 // CIR:         cir.get_element inbounds %[[ROW]][%{{.*}} : !s64i] : 
!cir.ptr<!cir.array<!cir.double x 10>> -> !cir.ptr<!cir.double>
 
 // LLVM-LABEL: define hidden double @param3d(
-// LLVM:         %[[PLANE:.*]] = getelementptr [2 x [5 x [10 x double]]], ptr
-// LLVM:         %[[ROW:.*]] = getelementptr [5 x [10 x double]], ptr 
%[[PLANE]],
-// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]],
+// LLVM:         %[[PLANE:.*]] = getelementptr [2 x [5 x [10 x double]]], ptr 
%{{.*}}, i64 0, i64 %{{.*}}
+// LLVM:         %[[ROW:.*]] = getelementptr [5 x [10 x double]], ptr 
%[[PLANE]], i64 0, i64 %{{.*}}
+// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]], i64 0, 
i64 %{{.*}}
 
 double local2d(int i, int j) {
   double a[5][10] = {{0}};
@@ -57,10 +57,10 @@ double local2d(int i, int j) {
 
 // LLVM-LABEL: define hidden double @local2d(
 // LLVMCIR:      alloca [5 x [10 x double]], align 8, addrspace(5)
-// LLVMCIR:      %[[ROW:.*]] = getelementptr inbounds [5 x [10 x double]], ptr
+// LLVMCIR:      %[[ROW:.*]] = getelementptr inbounds [5 x [10 x double]], ptr 
%{{.*}}, i64 0, i64 %{{.*}}
 // OGCG:         call align 8 ptr @__kmpc_alloc_shared(i64 400)
-// OGCG:         %[[ROW:.*]] = getelementptr [5 x [10 x double]], ptr
-// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]],
+// OGCG:         %[[ROW:.*]] = getelementptr [5 x [10 x double]], ptr %{{.*}}, 
i64 0, i64 %{{.*}}
+// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]], i64 0, 
i64 %{{.*}}
 
 double local3d(int i, int j, int k) {
   double a[2][5][10] = {{{0}}};
@@ -74,12 +74,12 @@ double local3d(int i, int j, int k) {
 
 // LLVM-LABEL: define hidden double @local3d(
 // LLVMCIR:      alloca [2 x [5 x [10 x double]]], align 8, addrspace(5)
-// LLVMCIR:      %[[PLANE:.*]] = getelementptr inbounds [2 x [5 x [10 x 
double]]], ptr
-// LLVMCIR:      %[[ROW:.*]] = getelementptr inbounds [5 x [10 x double]], ptr 
%[[PLANE]],
+// LLVMCIR:      %[[PLANE:.*]] = getelementptr inbounds [2 x [5 x [10 x 
double]]], ptr %{{.*}}, i64 0, i64 %{{.*}}
+// LLVMCIR:      %[[ROW:.*]] = getelementptr inbounds [5 x [10 x double]], ptr 
%[[PLANE]], i64 0, i64 %{{.*}}
 // OGCG:         call align 8 ptr @__kmpc_alloc_shared(i64 800)
-// OGCG:         %[[PLANE:.*]] = getelementptr [2 x [5 x [10 x double]]], ptr
-// OGCG:         %[[ROW:.*]] = getelementptr [5 x [10 x double]], ptr 
%[[PLANE]],
-// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]],
+// OGCG:         %[[PLANE:.*]] = getelementptr [2 x [5 x [10 x double]]], ptr 
%{{.*}}, i64 0, i64 %{{.*}}
+// OGCG:         %[[ROW:.*]] = getelementptr [5 x [10 x double]], ptr 
%[[PLANE]], i64 0, i64 %{{.*}}
+// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]], i64 0, 
i64 %{{.*}}
 
 double stride3d(int i, int j, int k) {
   double a[2][5][10] = {{{0}}};
@@ -96,9 +96,9 @@ double stride3d(int i, int j, int k) {
 
 // LLVM-LABEL: define hidden double @stride3d(
 // LLVMCIR:      alloca [2 x [5 x [10 x double]]], align 8, addrspace(5)
-// LLVMCIR:      %[[ROW:.*]] = getelementptr inbounds [5 x [10 x double]], ptr
+// LLVMCIR:      %[[ROW:.*]] = getelementptr inbounds [5 x [10 x double]], ptr 
%{{.*}}, i64 0, i64 %{{.*}}
 // OGCG:         call align 8 ptr @__kmpc_alloc_shared(i64 800)
-// OGCG:         %[[ROW:.*]] = getelementptr [5 x [10 x double]], ptr %{{.*}}, 
i64 0, i64
-// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]],
+// OGCG:         %[[ROW:.*]] = getelementptr [5 x [10 x double]], ptr %{{.*}}, 
i64 0, i64 %{{.*}}
+// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]], i64 0, 
i64 %{{.*}}
 
 #pragma omp end declare target
diff --git a/clang/test/CIR/Lowering/array.cpp 
b/clang/test/CIR/Lowering/array.cpp
index 3a4a94bc900e19..14b7a17f58ee26 100644
--- a/clang/test/CIR/Lowering/array.cpp
+++ b/clang/test/CIR/Lowering/array.cpp
@@ -51,10 +51,10 @@ void func() {
 // CHECK-NEXT: %[[ARR_ALLOCA:.*]] = alloca [10 x i32], align 16
 // CHECK-NEXT: %[[INIT:.*]] = alloca i32, align 4
 // CHECK-NEXT: %[[INIT_2:.*]] = alloca i32, align 4
-// CHECK-NEXT: %[[ELE_PTR:.*]] = getelementptr inbounds [10 x i32], ptr 
%[[ARR_ALLOCA]], i32 0, i64 0
+// CHECK-NEXT: %[[ELE_PTR:.*]] = getelementptr inbounds [10 x i32], ptr 
%[[ARR_ALLOCA]], i64 0, i64 0
 // CHECK-NEXT: %[[TMP:.*]] = load i32, ptr %[[ELE_PTR]], align 16
 // CHECK-NEXT: store i32 %[[TMP]], ptr %[[INIT]], align 4
-// CHECK-NEXT: %[[ELE_PTR:.*]] = getelementptr inbounds [10 x i32], ptr 
%[[ARR_ALLOCA]], i32 0, i64 1
+// CHECK-NEXT: %[[ELE_PTR:.*]] = getelementptr inbounds [10 x i32], ptr 
%[[ARR_ALLOCA]], i64 0, i64 1
 // CHECK-NEXT: %[[TMP:.*]] = load i32, ptr %[[ELE_PTR]], align 4
 // CHECK-NEXT: store i32 %[[TMP]], ptr %[[INIT_2]], align 4
 
@@ -82,8 +82,8 @@ void func4() {
 // CHECK:  %[[ARR_ALLOCA:.*]] = alloca [2 x [1 x i32]], align 4
 // CHECK:  %[[INIT:.*]] = alloca i32, align 4
 // CHECK:  call void @llvm.memcpy{{.*}}(ptr align 4 %[[ARR_ALLOCA]], ptr align 
4 @[[FUNC4_ARR]], i64 8, i1 false)
-// CHECK:  %[[ARR_1:.*]] = getelementptr inbounds [2 x [1 x i32]], ptr 
%[[ARR_ALLOCA]], i32 0, i64 1
-// CHECK:  %[[ELE_PTR:.*]] = getelementptr inbounds [1 x i32], ptr %[[ARR_1]], 
i32 0, i64 0
+// CHECK:  %[[ARR_1:.*]] = getelementptr inbounds [2 x [1 x i32]], ptr 
%[[ARR_ALLOCA]], i64 0, i64 1
+// CHECK:  %[[ELE_PTR:.*]] = getelementptr inbounds [1 x i32], ptr %[[ARR_1]], 
i64 0, i64 0
 // CHECK:  %[[TMP:.*]] = load i32, ptr %[[ELE_PTR]], align 4
 // CHECK:  store i32 %[[TMP]], ptr %[[INIT]], align 4
 
diff --git a/clang/test/CIR/Lowering/get-element.cir 
b/clang/test/CIR/Lowering/get-element.cir
index 7d3b34334be5d2..3d59542d6e9dd5 100644
--- a/clang/test/CIR/Lowering/get-element.cir
+++ b/clang/test/CIR/Lowering/get-element.cir
@@ -1,6 +1,7 @@
 // RUN: cir-translate -cir-to-llvmir --disable-cc-lowering -o %t.ll %s
 // RUN: FileCheck --input-file=%t.ll -check-prefix=LLVM %s
 
+!s16i = !cir.int<s, 16>
 !s32i = !cir.int<s, 32>
 !s64i = !cir.int<s, 64>
 !u64i = !cir.int<u, 64>
@@ -21,6 +22,11 @@ module attributes {cir.triple = "x86_64-unknown-linux-gnu"} {
     cir.return %0 : !cir.ptr<!s32i>
   }
 
+  cir.func @s16_index(%arg0: !cir.ptr<!cir.array<!s32i x 4>>, %arg1: !s16i) -> 
!cir.ptr<!s32i> {
+    %0 = cir.get_element inbounds %arg0[%arg1 : !s16i] : 
!cir.ptr<!cir.array<!s32i x 4>> -> !cir.ptr<!s32i>
+    cir.return %0 : !cir.ptr<!s32i>
+  }
+
   cir.func @inbounds_nuw(%arg0: !cir.ptr<!cir.array<!s32i x 4>>, %arg1: !u64i) 
-> !cir.ptr<!s32i> {
     %0 = cir.get_element inbounds nuw %arg0[%arg1 : !u64i] : 
!cir.ptr<!cir.array<!s32i x 4>> -> !cir.ptr<!s32i>
     cir.return %0 : !cir.ptr<!s32i>
@@ -28,13 +34,17 @@ module attributes {cir.triple = "x86_64-unknown-linux-gnu"} 
{
 }
 
 // LLVM-LABEL: define ptr @plain(
-// LLVM:         getelementptr [4 x i32], ptr %{{.*}}, i32 0, i64 %{{.*}}
+// LLVM:         getelementptr [4 x i32], ptr %{{.*}}, i64 0, i64 %{{.*}}
 
 // LLVM-LABEL: define ptr @inbounds(
-// LLVM:         getelementptr inbounds [4 x i32], ptr %{{.*}}, i32 0, i64 
%{{.*}}
+// LLVM:         getelementptr inbounds [4 x i32], ptr %{{.*}}, i64 0, i64 
%{{.*}}
 
 // LLVM-LABEL: define ptr @nuw(
-// LLVM:         getelementptr nuw [4 x i32], ptr %{{.*}}, i32 0, i64 %{{.*}}
+// LLVM:         getelementptr nuw [4 x i32], ptr %{{.*}}, i64 0, i64 %{{.*}}
+
+// A block-argument index is not widened, so the zero takes its i16 type.
+// LLVM-LABEL: define ptr @s16_index(
+// LLVM:         getelementptr inbounds [4 x i32], ptr %{{.*}}, i16 0, i16 
%{{.*}}
 
 // LLVM-LABEL: define ptr @inbounds_nuw(
-// LLVM:         getelementptr inbounds nuw [4 x i32], ptr %{{.*}}, i32 0, i64 
%{{.*}}
+// LLVM:         getelementptr inbounds nuw [4 x i32], ptr %{{.*}}, i64 0, i64 
%{{.*}}

>From b743533a69cfb6d6b411b340d32b938280f7c41f Mon Sep 17 00:00:00 2001
From: Adam Smith <[email protected]>
Date: Mon, 16 Nov 2026 10:52:07 -0800
Subject: [PATCH 2/2] [CIR] Address reviewer feedback

Assisted-by: Cursor / Claude Opus 5.5
---
 .../CodeGenOpenMP/device-array-subscript.c    | 36 +++++++++----------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/clang/test/CIR/CodeGenOpenMP/device-array-subscript.c 
b/clang/test/CIR/CodeGenOpenMP/device-array-subscript.c
index 72aa2a973afa9b..8adcf70f321801 100644
--- a/clang/test/CIR/CodeGenOpenMP/device-array-subscript.c
+++ b/clang/test/CIR/CodeGenOpenMP/device-array-subscript.c
@@ -17,8 +17,8 @@ double param2d(double (*p)[5][10], int i, int j) { return 
(*p)[i][j]; }
 // CIR:         cir.get_element inbounds %{{.*}}[%{{.*}} : !s64i] : 
!cir.ptr<!cir.array<!cir.double x 10>> -> !cir.ptr<!cir.double>
 
 // LLVM-LABEL: define hidden double @param2d(
-// LLVM:         %[[ROW:.*]] = getelementptr [5 x [10 x double]], ptr %{{.*}}, 
i64 0, i64 %{{.*}}
-// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]], i64 0, 
i64 %{{.*}}
+// LLVM:         %[[ROW:.*]] = getelementptr [5 x [10 x double]], ptr
+// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]],
 
 double uparam2d(double (*p)[5][10], unsigned i, int j) { return (*p)[i][j]; }
 
@@ -27,8 +27,8 @@ double uparam2d(double (*p)[5][10], unsigned i, int j) { 
return (*p)[i][j]; }
 // CIR:         cir.get_element inbounds %{{.*}}[%{{.*}} : !s64i] : 
!cir.ptr<!cir.array<!cir.double x 10>> -> !cir.ptr<!cir.double>
 
 // LLVM-LABEL: define hidden double @uparam2d(
-// LLVM:         %[[ROW:.*]] = getelementptr nuw [5 x [10 x double]], ptr 
%{{.*}}, i64 0, i64 %{{.*}}
-// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]], i64 0, 
i64 %{{.*}}
+// LLVM:         %[[ROW:.*]] = getelementptr nuw [5 x [10 x double]], ptr
+// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]],
 
 double param3d(double (*p)[2][5][10], int i, int j, int k) {
   return (*p)[i][j][k];
@@ -40,9 +40,9 @@ double param3d(double (*p)[2][5][10], int i, int j, int k) {
 // CIR:         cir.get_element inbounds %[[ROW]][%{{.*}} : !s64i] : 
!cir.ptr<!cir.array<!cir.double x 10>> -> !cir.ptr<!cir.double>
 
 // LLVM-LABEL: define hidden double @param3d(
-// LLVM:         %[[PLANE:.*]] = getelementptr [2 x [5 x [10 x double]]], ptr 
%{{.*}}, i64 0, i64 %{{.*}}
-// LLVM:         %[[ROW:.*]] = getelementptr [5 x [10 x double]], ptr 
%[[PLANE]], i64 0, i64 %{{.*}}
-// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]], i64 0, 
i64 %{{.*}}
+// LLVM:         %[[PLANE:.*]] = getelementptr [2 x [5 x [10 x double]]], ptr
+// LLVM:         %[[ROW:.*]] = getelementptr [5 x [10 x double]], ptr 
%[[PLANE]],
+// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]],
 
 double local2d(int i, int j) {
   double a[5][10] = {{0}};
@@ -57,10 +57,10 @@ double local2d(int i, int j) {
 
 // LLVM-LABEL: define hidden double @local2d(
 // LLVMCIR:      alloca [5 x [10 x double]], align 8, addrspace(5)
-// LLVMCIR:      %[[ROW:.*]] = getelementptr inbounds [5 x [10 x double]], ptr 
%{{.*}}, i64 0, i64 %{{.*}}
+// LLVMCIR:      %[[ROW:.*]] = getelementptr inbounds [5 x [10 x double]], ptr
 // OGCG:         call align 8 ptr @__kmpc_alloc_shared(i64 400)
-// OGCG:         %[[ROW:.*]] = getelementptr [5 x [10 x double]], ptr %{{.*}}, 
i64 0, i64 %{{.*}}
-// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]], i64 0, 
i64 %{{.*}}
+// OGCG:         %[[ROW:.*]] = getelementptr [5 x [10 x double]], ptr
+// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]],
 
 double local3d(int i, int j, int k) {
   double a[2][5][10] = {{{0}}};
@@ -74,12 +74,12 @@ double local3d(int i, int j, int k) {
 
 // LLVM-LABEL: define hidden double @local3d(
 // LLVMCIR:      alloca [2 x [5 x [10 x double]]], align 8, addrspace(5)
-// LLVMCIR:      %[[PLANE:.*]] = getelementptr inbounds [2 x [5 x [10 x 
double]]], ptr %{{.*}}, i64 0, i64 %{{.*}}
-// LLVMCIR:      %[[ROW:.*]] = getelementptr inbounds [5 x [10 x double]], ptr 
%[[PLANE]], i64 0, i64 %{{.*}}
+// LLVMCIR:      %[[PLANE:.*]] = getelementptr inbounds [2 x [5 x [10 x 
double]]], ptr
+// LLVMCIR:      %[[ROW:.*]] = getelementptr inbounds [5 x [10 x double]], ptr 
%[[PLANE]],
 // OGCG:         call align 8 ptr @__kmpc_alloc_shared(i64 800)
-// OGCG:         %[[PLANE:.*]] = getelementptr [2 x [5 x [10 x double]]], ptr 
%{{.*}}, i64 0, i64 %{{.*}}
-// OGCG:         %[[ROW:.*]] = getelementptr [5 x [10 x double]], ptr 
%[[PLANE]], i64 0, i64 %{{.*}}
-// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]], i64 0, 
i64 %{{.*}}
+// OGCG:         %[[PLANE:.*]] = getelementptr [2 x [5 x [10 x double]]], ptr
+// OGCG:         %[[ROW:.*]] = getelementptr [5 x [10 x double]], ptr 
%[[PLANE]],
+// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]],
 
 double stride3d(int i, int j, int k) {
   double a[2][5][10] = {{{0}}};
@@ -96,9 +96,9 @@ double stride3d(int i, int j, int k) {
 
 // LLVM-LABEL: define hidden double @stride3d(
 // LLVMCIR:      alloca [2 x [5 x [10 x double]]], align 8, addrspace(5)
-// LLVMCIR:      %[[ROW:.*]] = getelementptr inbounds [5 x [10 x double]], ptr 
%{{.*}}, i64 0, i64 %{{.*}}
+// LLVMCIR:      %[[ROW:.*]] = getelementptr inbounds [5 x [10 x double]], ptr
 // OGCG:         call align 8 ptr @__kmpc_alloc_shared(i64 800)
-// OGCG:         %[[ROW:.*]] = getelementptr [5 x [10 x double]], ptr %{{.*}}, 
i64 0, i64 %{{.*}}
-// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]], i64 0, 
i64 %{{.*}}
+// OGCG:         %[[ROW:.*]] = getelementptr [5 x [10 x double]], ptr %{{.*}}, 
i64 0, i64
+// LLVM:         getelementptr inbounds [10 x double], ptr %[[ROW]],
 
 #pragma omp end declare target

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to