Skip to content

Commit

Permalink
[CIR][LowerToLLVM] fixup! CIR generated LLVM code for pointer arithme…
Browse files Browse the repository at this point in the history
…tic should

have inbounds.
  • Loading branch information
liusy58 committed Dec 4, 2024
1 parent eacaabb commit 0362c64
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 33 deletions.
5 changes: 3 additions & 2 deletions clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,8 +851,9 @@ mlir::LogicalResult CIRToLLVMPtrStrideOpLowering::matchAndRewrite(
}
}

rewriter.replaceOpWithNewOp<mlir::LLVM::GEPOp>(
ptrStrideOp, resultTy, elementTy, adaptor.getBase(), index);
rewriter.replaceOpWithNewOp<mlir::LLVM::GEPOp>(ptrStrideOp, resultTy,
elementTy, adaptor.getBase(),
index, /*inbounds=*/true);
return mlir::success();
}

Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/CodeGen/address-space-conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void test_side_effect(pi1_t b) {
// CIR: %[[#CAST:]] = cir.const #cir.ptr<null> : !cir.ptr<!s32i, addrspace(target<2>)>
// CIR-NEXT: cir.store %[[#CAST]], %{{[0-9]+}} : !cir.ptr<!s32i, addrspace(target<2>)>, !cir.ptr<!cir.ptr<!s32i, addrspace(target<2>)>>

// LLVM: %{{[0-9]+}} = getelementptr i32, ptr addrspace(1) %{{[0-9]+}}, i64 1
// LLVM: %{{[0-9]+}} = getelementptr inbounds i32, ptr addrspace(1) %{{[0-9]+}}, i64 1
// LLVM: store ptr addrspace(2) null, ptr %{{[0-9]+}}, align 8

}
2 changes: 1 addition & 1 deletion clang/test/CIR/CodeGen/clear_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ char buffer[32] = "This is a largely unused buffer";
// CIR: cir.clear_cache %[[VAL_3]] : !cir.ptr<!void>, %[[VAL_8]],

// LLVM-LABEL: main
// LLVM: call void @llvm.clear_cache(ptr @buffer, ptr getelementptr (i8, ptr @buffer, i64 32))
// LLVM: call void @llvm.clear_cache(ptr @buffer, ptr getelementptr inbounds (i8, ptr @buffer, i64 32))

int main(void) {
__builtin___clear_cache(buffer, buffer+32);
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CIR/CodeGen/initlist-ptr-ptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ void test() {
// LLVM: [[SCOPE_START]]: ; preds = %0
// LLVM: [[PTR_FIRST_ELEM:%.*]] = getelementptr ptr, ptr [[ELEM_ARRAY_PTR]], i32 0
// LLVM: store ptr @.str, ptr [[PTR_FIRST_ELEM]], align 8
// LLVM: [[PTR_SECOND_ELEM:%.*]] = getelementptr ptr, ptr [[PTR_FIRST_ELEM]], i64 1
// LLVM: [[PTR_SECOND_ELEM:%.*]] = getelementptr inbounds ptr, ptr [[PTR_FIRST_ELEM]], i64 1
// LLVM: store ptr @.str.1, ptr [[PTR_SECOND_ELEM]], align 8
// LLVM: [[INIT_START_FLD_PTR:%.*]] = getelementptr %"class.std::initializer_list<const char *>", ptr [[INIT_STRUCT]], i32 0, i32 0
// LLVM: store ptr [[PTR_FIRST_ELEM]], ptr [[INIT_START_FLD_PTR]], align 8
// LLVM: [[ELEM_ARRAY_END:%.*]] = getelementptr ptr, ptr [[PTR_FIRST_ELEM]], i64 2
// LLVM: [[ELEM_ARRAY_END:%.*]] = getelementptr inbounds ptr, ptr [[PTR_FIRST_ELEM]], i64 2
// LLVM: [[INIT_END_FLD_PTR:%.*]] = getelementptr %"class.std::initializer_list<const char *>", ptr [[INIT_STRUCT]], i32 0, i32 1
// LLVM: store ptr [[ELEM_ARRAY_END]], ptr [[INIT_END_FLD_PTR]], align 8
// LLVM: [[ARG2PASS:%.*]] = load %"class.std::initializer_list<const char *>", ptr [[INIT_STRUCT]], align 8
Expand Down
16 changes: 8 additions & 8 deletions clang/test/CIR/CodeGen/pointer-arith-ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void *f2(void *a, int b) { return a + b; }
// LLVM: %[[PTR:.*]] = load ptr, ptr {{.*}}, align 8
// LLVM: %[[TOEXT:.*]] = load i32, ptr {{.*}}, align 4
// LLVM: %[[STRIDE:.*]] = sext i32 %[[TOEXT]] to i64
// LLVM: getelementptr i8, ptr %[[PTR]], i64 %[[STRIDE]]
// LLVM: getelementptr inbounds i8, ptr %[[PTR]], i64 %[[STRIDE]]

// These test the same paths above, just make sure it does not crash.
void *f2_0(void *a, int b) { return &a[b]; }
Expand All @@ -28,7 +28,7 @@ void *f3_1(int a, void *b) { return (a += b); }
// CIR: cir.cast(ptr_to_int, %[[NEW_PTR]] : !cir.ptr<!void>), !s32i

// LLVM-LABEL: @f3_1
// LLVM: %[[NEW_PTR:.*]] = getelementptr
// LLVM: %[[NEW_PTR:.*]] = getelementptr inbounds
// LLVM: ptrtoint ptr %[[NEW_PTR]] to i32

void *f4(void *a, int b) { return a - b; }
Expand All @@ -43,7 +43,7 @@ void *f4(void *a, int b) { return a - b; }
// LLVM: %[[TOEXT:.*]] = load i32, ptr {{.*}}, align 4
// LLVM: %[[STRIDE:.*]] = sext i32 %[[TOEXT]] to i64
// LLVM: %[[SUB:.*]] = sub i64 0, %[[STRIDE]]
// LLVM: getelementptr i8, ptr %[[PTR]], i64 %[[SUB]]
// LLVM: getelementptr inbounds i8, ptr %[[PTR]], i64 %[[SUB]]

// Similar to f4, just make sure it does not crash.
void *f4_1(void *a, int b) { return (a -= b); }
Expand All @@ -58,7 +58,7 @@ FP f5(FP a, int b) { return a + b; }
// LLVM: %[[PTR:.*]] = load ptr, ptr {{.*}}, align 8
// LLVM: %[[TOEXT:.*]] = load i32, ptr {{.*}}, align 4
// LLVM: %[[STRIDE:.*]] = sext i32 %[[TOEXT]] to i64
// LLVM: getelementptr i8, ptr %[[PTR]], i64 %[[STRIDE]]
// LLVM: getelementptr inbounds i8, ptr %[[PTR]], i64 %[[STRIDE]]

// These test the same paths above, just make sure it does not crash.
FP f5_1(FP a, int b) { return (a += b); }
Expand All @@ -77,7 +77,7 @@ FP f7(FP a, int b) { return a - b; }
// LLVM: %[[TOEXT:.*]] = load i32, ptr {{.*}}, align 4
// LLVM: %[[STRIDE:.*]] = sext i32 %[[TOEXT]] to i64
// LLVM: %[[SUB:.*]] = sub i64 0, %[[STRIDE]]
// LLVM: getelementptr i8, ptr %[[PTR]], i64 %[[SUB]]
// LLVM: getelementptr inbounds i8, ptr %[[PTR]], i64 %[[SUB]]

// Similar to f7, just make sure it does not crash.
FP f7_1(FP a, int b) { return (a -= b); }
Expand All @@ -93,7 +93,7 @@ void f8(void *a, int b) { return *(a + b); }
// LLVM: %[[PTR:.*]] = load ptr, ptr {{.*}}, align 8
// LLVM: %[[TOEXT:.*]] = load i32, ptr {{.*}}, align 4
// LLVM: %[[STRIDE:.*]] = sext i32 %[[TOEXT]] to i64
// LLVM: getelementptr i8, ptr %[[PTR]], i64 %[[STRIDE]]
// LLVM: getelementptr inbounds i8, ptr %[[PTR]], i64 %[[STRIDE]]
// LLVM: ret void

void f8_1(void *a, int b) { return a[b]; }
Expand All @@ -107,7 +107,7 @@ void f8_1(void *a, int b) { return a[b]; }
// LLVM: %[[PTR:.*]] = load ptr, ptr {{.*}}, align 8
// LLVM: %[[TOEXT:.*]] = load i32, ptr {{.*}}, align 4
// LLVM: %[[STRIDE:.*]] = sext i32 %[[TOEXT]] to i64
// LLVM: getelementptr i8, ptr %[[PTR]], i64 %[[STRIDE]]
// LLVM: getelementptr inbounds i8, ptr %[[PTR]], i64 %[[STRIDE]]
// LLVM: ret void

unsigned char *p(unsigned int x) {
Expand All @@ -121,4 +121,4 @@ unsigned char *p(unsigned int x) {
// CIR: cir.ptr_stride({{.*}} : !cir.ptr<!u8i>, %[[SUB]] : !u32i), !cir.ptr<!u8i>

// LLVM-LABEL: @p
// LLVM: getelementptr i8, ptr {{.*}}
// LLVM: getelementptr inbounds i8, ptr {{.*}}
6 changes: 6 additions & 0 deletions clang/test/CIR/CodeGen/ptr_stride.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -fclangir -emit-llvm %s -o %t.ll
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM

void foo(int *iptr) { iptr + 2; }

// LLVM: getelementptr inbounds
4 changes: 2 additions & 2 deletions clang/test/CIR/CodeGen/var-arg-float.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ double f1(int n, ...) {
// LLVM-NEXT: [[VR_TOP_P:%.*]] = getelementptr %struct.__va_list, ptr [[VARLIST]], i32 0, i32 2
// LLVM-NEXT: [[VR_TOP:%.*]] = load ptr, ptr [[VR_TOP_P]], align 8
// LLVM-NEXT: [[EXT64_VR_OFFS:%.*]] = sext i32 [[VR_OFFS]] to i64
// LLVM-NEXT: [[IN_REG_OUTPUT:%.*]] = getelementptr i8, ptr [[VR_TOP]], i64 [[EXT64_VR_OFFS]]
// LLVM-NEXT: [[IN_REG_OUTPUT:%.*]] = getelementptr inbounds i8, ptr [[VR_TOP]], i64 [[EXT64_VR_OFFS]]
// LLVM-NEXT: br label %[[BB_END:.*]]

// LLVM: [[BB_ON_STACK]]: ;
// LLVM-NEXT: [[STACK_P:%.*]] = getelementptr %struct.__va_list, ptr [[VARLIST]], i32 0, i32 0
// LLVM-NEXT: [[STACK_V:%.*]] = load ptr, ptr [[STACK_P]], align 8
// LLVM-NEXT: [[NEW_STACK_V:%.*]] = getelementptr i8, ptr [[STACK_V]], i64 8
// LLVM-NEXT: [[NEW_STACK_V:%.*]] = getelementptr inbounds i8, ptr [[STACK_V]], i64 8
// LLVM-NEXT: store ptr [[NEW_STACK_V]], ptr [[STACK_P]], align 8
// LLVM-NEXT: br label %[[BB_END]]

Expand Down
4 changes: 2 additions & 2 deletions clang/test/CIR/CodeGen/var-arg-scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ void f1(__builtin_va_list c) {
// LLVM-NEXT: [[GR_TOP_P:%.*]] = getelementptr %struct.__va_list, ptr [[VARLIST]], i32 0, i32 1
// LLVM-NEXT: [[GR_TOP:%.*]] = load ptr, ptr [[GR_TOP_P]], align 8
// LLVM-NEXT: [[EXT64_GR_OFFS:%.*]] = sext i32 [[GR_OFFS]] to i64
// LLVM-NEXT: [[IN_REG_OUTPUT:%.*]] = getelementptr i8, ptr [[GR_TOP]], i64 [[EXT64_GR_OFFS]]
// LLVM-NEXT: [[IN_REG_OUTPUT:%.*]] = getelementptr inbounds i8, ptr [[GR_TOP]], i64 [[EXT64_GR_OFFS]]
// LLVM-NEXT: br label %[[BB_END:.*]]

// LLVM: [[BB_ON_STACK]]: ;
// LLVM-NEXT: [[STACK_P:%.*]] = getelementptr %struct.__va_list, ptr [[VARLIST]], i32 0, i32 0
// LLVM-NEXT: [[STACK_V:%.*]] = load ptr, ptr [[STACK_P]], align 8
// LLVM-NEXT: [[NEW_STACK_V:%.*]] = getelementptr i8, ptr [[STACK_V]], i64 8
// LLVM-NEXT: [[NEW_STACK_V:%.*]] = getelementptr inbounds i8, ptr [[STACK_V]], i64 8
// LLVM-NEXT: store ptr [[NEW_STACK_V]], ptr [[STACK_P]], align 8
// LLVM-NEXT: br label %[[BB_END]]

Expand Down
4 changes: 2 additions & 2 deletions clang/test/CIR/CodeGen/var-arg.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ int f1(int n, ...) {
// LLVM-NEXT: [[GR_TOP_P:%.*]] = getelementptr %struct.__va_list, ptr [[VARLIST]], i32 0, i32 1
// LLVM-NEXT: [[GR_TOP:%.*]] = load ptr, ptr [[GR_TOP_P]], align 8
// LLVM-NEXT: [[EXT64_GR_OFFS:%.*]] = sext i32 [[GR_OFFS]] to i64
// LLVM-NEXT: [[IN_REG_OUTPUT:%.*]] = getelementptr i8, ptr [[GR_TOP]], i64 [[EXT64_GR_OFFS]]
// LLVM-NEXT: [[IN_REG_OUTPUT:%.*]] = getelementptr inbounds i8, ptr [[GR_TOP]], i64 [[EXT64_GR_OFFS]]
// LLVM-NEXT: br label %[[BB_END:.*]]

// LLVM: [[BB_ON_STACK]]: ;
// LLVM-NEXT: [[STACK_P:%.*]] = getelementptr %struct.__va_list, ptr [[VARLIST]], i32 0, i32 0
// LLVM-NEXT: [[STACK_V:%.*]] = load ptr, ptr [[STACK_P]], align 8
// LLVM-NEXT: [[NEW_STACK_V:%.*]] = getelementptr i8, ptr [[STACK_V]], i64 8
// LLVM-NEXT: [[NEW_STACK_V:%.*]] = getelementptr inbounds i8, ptr [[STACK_V]], i64 8
// LLVM-NEXT: store ptr [[NEW_STACK_V]], ptr [[STACK_P]], align 8
// LLVM-NEXT: br label %[[BB_END]]

Expand Down
8 changes: 4 additions & 4 deletions clang/test/CIR/CodeGen/virtual-base-cast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ A* a() { return x; }

// FIXME: this version should include null check.
// LLVM-LABEL: @_Z1av()
// LLVM: %[[OFFSET_OFFSET:.*]] = getelementptr i8, ptr {{.*}}, i64 -32
// LLVM: %[[OFFSET_OFFSET:.*]] = getelementptr inbounds i8, ptr {{.*}}, i64 -32
// LLVM: %[[OFFSET_PTR:.*]] = load i64, ptr %[[OFFSET_OFFSET]], align 8
// LLVM: %[[VBASE_ADDR:.*]] = getelementptr i8, ptr {{.*}}, i64 %[[OFFSET_PTR]]
// LLVM: %[[VBASE_ADDR:.*]] = getelementptr inbounds i8, ptr {{.*}}, i64 %[[OFFSET_PTR]]
// LLVM: store ptr %[[VBASE_ADDR]], ptr {{.*}}, align 8

B* b() { return x; }
Expand All @@ -46,8 +46,8 @@ BB* d() { return y; }
// CIR: cir.binop(add, %[[OFFSET]], %[[ADJUST]]) : !s64i

// LLVM-LABEL: @_Z1dv
// LLVM: %[[OFFSET_OFFSET:.*]] = getelementptr i8, ptr {{.*}}, i64 -48
// LLVM: %[[OFFSET_OFFSET:.*]] = getelementptr inbounds i8, ptr {{.*}}, i64 -48
// LLVM: %[[OFFSET_PTR:.*]] = load i64, ptr %[[OFFSET_OFFSET]], align 8
// LLVM: %[[ADJUST:.*]] = add i64 %[[OFFSET_PTR]], 16
// LLVM: %[[VBASE_ADDR:.*]] = getelementptr i8, ptr {{.*}}, i64 %[[ADJUST]]
// LLVM: %[[VBASE_ADDR:.*]] = getelementptr inbounds i8, ptr {{.*}}, i64 %[[ADJUST]]
// LLVM: store ptr %[[VBASE_ADDR]],
4 changes: 2 additions & 2 deletions clang/test/CIR/Lowering/data-member.cir
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ module @test attributes {
}
// MLIR: llvm.func @get_runtime_member(%[[ARG0:.+]]: !llvm.ptr, %[[ARG1:.+]]: i64) -> !llvm.ptr
// MLIR-NEXT: %[[#PTR:]] = llvm.bitcast %[[ARG0]] : !llvm.ptr to !llvm.ptr
// MLIR-NEXT: %[[#VAL:]] = llvm.getelementptr %[[#PTR]][%[[ARG1]]] : (!llvm.ptr, i64) -> !llvm.ptr, i8
// MLIR-NEXT: %[[#VAL:]] = llvm.getelementptr inbounds %[[#PTR]][%[[ARG1]]] : (!llvm.ptr, i64) -> !llvm.ptr, i8
// MLIR-NEXT: %[[#RET:]] = llvm.bitcast %[[#VAL]] : !llvm.ptr to !llvm.ptr
// MLIR-NEXT: llvm.return %[[#RET]] : !llvm.ptr
// MLIR-NEXT: }

// LLVM: define ptr @get_runtime_member(ptr %[[ARG0:.+]], i64 %[[ARG1:.+]])
// LLVM-NEXT: %[[#VAL:]] = getelementptr i8, ptr %[[ARG0]], i64 %[[ARG1]]
// LLVM-NEXT: %[[#VAL:]] = getelementptr inbounds i8, ptr %[[ARG0]], i64 %[[ARG1]]
// LLVM-NEXT: ret ptr %[[#VAL]]
// LLVM-NEXT: }
}
4 changes: 2 additions & 2 deletions clang/test/CIR/Lowering/dot.cir
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ module {
// MLIR: %[[VAL_23:.*]] = llvm.load %[[VAL_4]] {alignment = 8 : i64} : !llvm.ptr -> !llvm.ptr
// MLIR: %[[VAL_24:.*]] = llvm.load %[[VAL_2]] {alignment = 4 : i64} : !llvm.ptr -> i32
// MLIR: %[[VAL_25:.*]] = llvm.sext %[[VAL_24]] : i32 to i64
// MLIR: %[[VAL_26:.*]] = llvm.getelementptr %[[VAL_23]]{{\[}}%[[VAL_25]]] : (!llvm.ptr, i64) -> !llvm.ptr, f64
// MLIR: %[[VAL_26:.*]] = llvm.getelementptr inbounds %[[VAL_23]]{{\[}}%[[VAL_25]]] : (!llvm.ptr, i64) -> !llvm.ptr, f64
// MLIR: %[[VAL_27:.*]] = llvm.load %[[VAL_26]] {alignment = 8 : i64} : !llvm.ptr -> f64
// MLIR: %[[VAL_28:.*]] = llvm.load %[[VAL_6]] {alignment = 8 : i64} : !llvm.ptr -> !llvm.ptr
// MLIR: %[[VAL_29:.*]] = llvm.load %[[VAL_2]] {alignment = 4 : i64} : !llvm.ptr -> i32
// MLIR: %[[VAL_30:.*]] = llvm.sext %[[VAL_29]] : i32 to i64
// MLIR: %[[VAL_31:.*]] = llvm.getelementptr %[[VAL_28]]{{\[}}%[[VAL_30]]] : (!llvm.ptr, i64) -> !llvm.ptr, f64
// MLIR: %[[VAL_31:.*]] = llvm.getelementptr inbounds %[[VAL_28]]{{\[}}%[[VAL_30]]] : (!llvm.ptr, i64) -> !llvm.ptr, f64
// MLIR: %[[VAL_32:.*]] = llvm.load %[[VAL_31]] {alignment = 8 : i64} : !llvm.ptr -> f64
// MLIR: %[[VAL_33:.*]] = llvm.fmul %[[VAL_27]], %[[VAL_32]] : f64
// MLIR: %[[VAL_34:.*]] = llvm.load %[[VAL_12]] {alignment = 8 : i64} : !llvm.ptr -> f64
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/Lowering/globals.cir
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ module {
//MLIR: %[[LOAD:.*]] = llvm.load {{.*}} {alignment = 4 : i64} : !llvm.ptr -> i32
//MLIR: %[[RES6:.*]] = llvm.getelementptr %[[RES4]][0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<"struct.anon.1", (ptr)>
//MLIR: %[[RES5:.*]] = llvm.sext %[[LOAD]] : i32 to i64
//MLIR: %[[RES7:.*]] = llvm.getelementptr %[[RES6]][%[[RES5]]] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<"struct.anon.1", (ptr)>
//MLIR: %[[RES7:.*]] = llvm.getelementptr inbounds %[[RES6]][%[[RES5]]] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<"struct.anon.1", (ptr)>
//MLIR: %[[RES8:.*]] = llvm.getelementptr %[[RES7]][0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<"struct.anon.1", (ptr)>
//MLIR: %[[RES9:.*]] = llvm.load %[[RES8]] {alignment = 8 : i64} : !llvm.ptr -> !llvm.ptr
//MLIR: llvm.call %[[RES9]]({{.*}}) : !llvm.ptr, (i32) -> ()
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CIR/Lowering/ptrstride.cir
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ module {
// MLIR: %[[VAL_3:.*]] = llvm.load %[[VAL_2]] {alignment = 8 : i64} : !llvm.ptr -> !llvm.ptr
// MLIR: %[[VAL_4:.*]] = llvm.mlir.constant(1 : i32) : i32
// MLIR: %[[VAL_5:.*]] = llvm.sext %[[VAL_4]] : i32 to i64
// MLIR: %[[VAL_6:.*]] = llvm.getelementptr %[[VAL_3]]{{\[}}%[[VAL_5]]] : (!llvm.ptr, i64) -> !llvm.ptr, i32
// MLIR: %[[VAL_6:.*]] = llvm.getelementptr inbounds %[[VAL_3]]{{\[}}%[[VAL_5]]] : (!llvm.ptr, i64) -> !llvm.ptr, i32
// MLIR: %[[VAL_7:.*]] = llvm.load %[[VAL_6]] {alignment = 4 : i64} : !llvm.ptr -> i32
// MLIR: llvm.return

// MLIR-LABEL: @g
// MLIR: %0 = llvm.sext %arg1 : i32 to i64
// MLIR-NEXT: llvm.getelementptr %arg0[%0] : (!llvm.ptr, i64) -> !llvm.ptr, i32
// MLIR-NEXT: llvm.getelementptr inbounds %arg0[%0] : (!llvm.ptr, i64) -> !llvm.ptr, i32
4 changes: 2 additions & 2 deletions clang/test/CIR/Lowering/var-arg-x86_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ long double f2(int n, ...) {
// CHECK: [[OVERFLOW_AREA_P:%.+]] = getelementptr {{.*}} [[VA_LIST2]], i32 0, i32 2
// CHECK: [[OVERFLOW_AREA:%.+]] = load ptr, ptr [[OVERFLOW_AREA_P]]
// Ptr Mask Operations
// CHECK: [[OVERFLOW_AREA_OFFSET_ALIGNED:%.+]] = getelementptr i8, ptr [[OVERFLOW_AREA]], i64 15
// CHECK: [[OVERFLOW_AREA_OFFSET_ALIGNED:%.+]] = getelementptr inbounds i8, ptr [[OVERFLOW_AREA]], i64 15
// CHECK: [[OVERFLOW_AREA_OFFSET_ALIGNED_P:%.+]] = ptrtoint ptr [[OVERFLOW_AREA_OFFSET_ALIGNED]] to i32
// CHECK: [[MASKED:%.+]] = and i32 [[OVERFLOW_AREA_OFFSET_ALIGNED_P]], -16
// CHECK: [[DIFF:%.+]] = sub i32 [[OVERFLOW_AREA_OFFSET_ALIGNED_P]], [[MASKED]]
// CHECK: [[PTR_MASKED:%.+]] = getelementptr i8, ptr [[OVERFLOW_AREA_OFFSET_ALIGNED]], i32 [[DIFF]]
// CHECK: [[OVERFLOW_AREA_NEXT:%.+]] = getelementptr i8, ptr [[PTR_MASKED]], i64 16
// CHECK: [[OVERFLOW_AREA_NEXT:%.+]] = getelementptr inbounds i8, ptr [[PTR_MASKED]], i64 16
// CHECK: store ptr [[OVERFLOW_AREA_NEXT]], ptr [[OVERFLOW_AREA_P]]
// CHECK: [[VALUE:%.+]] = load x86_fp80, ptr [[PTR_MASKED]]
// CHECK: store x86_fp80 [[VALUE]], ptr [[RES]]
Expand Down

0 comments on commit 0362c64

Please sign in to comment.