Skip to content

Commit

Permalink
[CIR][LowerToLLVM] fixup! GEP with a constant offset should have inbo…
Browse files Browse the repository at this point in the history
…unds attribute
  • Loading branch information
liusy58 committed Dec 3, 2024
1 parent eacaabb commit d9b7c41
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 80 deletions.
41 changes: 22 additions & 19 deletions clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ lowerCirAttrAsValue(mlir::Operation *parentOp, cir::GlobalViewAttr globalAttr,
auto resTy = addrOp.getType();
auto eltTy = converter->convertType(sourceType);
addrOp = rewriter.create<mlir::LLVM::GEPOp>(loc, resTy, eltTy, addrOp,
indices, true);
indices, /*inbounds*/ true);
}

auto ptrTy = mlir::dyn_cast<cir::PointerType>(globalAttr.getType());
Expand Down 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 All @@ -873,17 +874,18 @@ mlir::LogicalResult CIRToLLVMBaseClassAddrOpLowering::matchAndRewrite(
}

if (baseClassOp.getAssumeNotNull()) {
rewriter.replaceOpWithNewOp<mlir::LLVM::GEPOp>(
baseClassOp, resultType, byteType, derivedAddr, offset);
rewriter.replaceOpWithNewOp<mlir::LLVM::GEPOp>(baseClassOp, resultType,
byteType, derivedAddr,
offset, /*inbounds*/ true);
} else {
auto loc = baseClassOp.getLoc();
mlir::Value isNull = rewriter.create<mlir::LLVM::ICmpOp>(
loc, mlir::LLVM::ICmpPredicate::eq, derivedAddr,
rewriter.create<mlir::LLVM::ZeroOp>(loc, derivedAddr.getType()));
mlir::Value adjusted = rewriter.create<mlir::LLVM::GEPOp>(
loc, resultType, byteType, derivedAddr, offset);
rewriter.replaceOpWithNewOp<mlir::LLVM::SelectOp>(baseClassOp, isNull,
derivedAddr, adjusted);
rewriter.replaceOpWithNewOp<mlir::LLVM::SelectOp>(
baseClassOp, isNull, derivedAddr, adjusted, /*inbounds*/ true);
}
return mlir::success();
}
Expand All @@ -900,16 +902,17 @@ mlir::LogicalResult CIRToLLVMDerivedClassAddrOpLowering::matchAndRewrite(
mlir::IntegerType::Signless);
if (derivedClassOp.getAssumeNotNull()) {
rewriter.replaceOpWithNewOp<mlir::LLVM::GEPOp>(derivedClassOp, resultType,
byteType, baseAddr, offset);
byteType, baseAddr, offset,
/*inbounds*/ true);
} else {
auto loc = derivedClassOp.getLoc();
mlir::Value isNull = rewriter.create<mlir::LLVM::ICmpOp>(
loc, mlir::LLVM::ICmpPredicate::eq, baseAddr,
rewriter.create<mlir::LLVM::ZeroOp>(loc, baseAddr.getType()));
mlir::Value adjusted = rewriter.create<mlir::LLVM::GEPOp>(
loc, resultType, byteType, baseAddr, offset);
rewriter.replaceOpWithNewOp<mlir::LLVM::SelectOp>(derivedClassOp, isNull,
baseAddr, adjusted);
rewriter.replaceOpWithNewOp<mlir::LLVM::SelectOp>(
derivedClassOp, isNull, baseAddr, adjusted, /*inbounds*/ true);
}
return mlir::success();
}
Expand Down Expand Up @@ -974,8 +977,8 @@ mlir::LogicalResult CIRToLLVMVTTAddrPointOpLowering::matchAndRewrite(
offsets.push_back(0);
offsets.push_back(adaptor.getOffset());
}
rewriter.replaceOpWithNewOp<mlir::LLVM::GEPOp>(op, resultType, eltType,
llvmAddr, offsets, true);
rewriter.replaceOpWithNewOp<mlir::LLVM::GEPOp>(
op, resultType, eltType, llvmAddr, offsets, /*inbounds*/ true);
return mlir::success();
}

Expand Down Expand Up @@ -1032,7 +1035,7 @@ mlir::LogicalResult CIRToLLVMCastOpLowering::matchAndRewrite(
auto elementTy = convertTy(ptrTy.getPointee());
auto offset = llvm::SmallVector<mlir::LLVM::GEPArg>{0};
rewriter.replaceOpWithNewOp<mlir::LLVM::GEPOp>(
castOp, targetType, elementTy, sourceValue, offset);
castOp, targetType, elementTy, sourceValue, offset, /*inbounds*/ true);
break;
}
case cir::CastKind::int_to_bool: {
Expand Down Expand Up @@ -3236,8 +3239,8 @@ mlir::LogicalResult CIRToLLVMGetMemberOpLowering::matchAndRewrite(
// is always zero. The second offset tell us which member it will access.
llvm::SmallVector<mlir::LLVM::GEPArg, 2> offset{0, op.getIndex()};
const auto elementTy = getTypeConverter()->convertType(structTy);
rewriter.replaceOpWithNewOp<mlir::LLVM::GEPOp>(op, llResTy, elementTy,
adaptor.getAddr(), offset);
rewriter.replaceOpWithNewOp<mlir::LLVM::GEPOp>(
op, llResTy, elementTy, adaptor.getAddr(), offset, /*inbounds*/ true);
return mlir::success();
}
case cir::StructType::Union:
Expand Down Expand Up @@ -3337,8 +3340,8 @@ mlir::LogicalResult CIRToLLVMVTableAddrPointOpLowering::matchAndRewrite(
}

assert(eltType && "Shouldn't ever be missing an eltType here");
rewriter.replaceOpWithNewOp<mlir::LLVM::GEPOp>(op, targetType, eltType,
symAddr, offsets, true);
rewriter.replaceOpWithNewOp<mlir::LLVM::GEPOp>(
op, targetType, eltType, symAddr, offsets, /*inbounds*/ true);

return mlir::success();
}
Expand Down Expand Up @@ -3837,8 +3840,8 @@ mlir::LogicalResult CIRToLLVMPtrMaskOpLowering::matchAndRewrite(
mlir::Value diff = rewriter.create<mlir::LLVM::SubOp>(loc, intPtr, masked);
rewriter.replaceOpWithNewOp<mlir::LLVM::GEPOp>(
op, getTypeConverter()->convertType(op.getType()),
mlir::IntegerType::get(moduleOp->getContext(), 8), adaptor.getPtr(),
diff);
mlir::IntegerType::get(moduleOp->getContext(), 8), adaptor.getPtr(), diff,
/*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
6 changes: 6 additions & 0 deletions clang/test/CIR/CodeGen/inbouds.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 i32,
10 changes: 5 additions & 5 deletions clang/test/CIR/CodeGen/initlist-ptr-ptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ void test() {
// LLVM: [[ELEM_ARRAY_PTR:%.*]] = alloca [2 x ptr], i64 1, align 8
// LLVM: br label %[[SCOPE_START:.*]]
// LLVM: [[SCOPE_START]]: ; preds = %0
// LLVM: [[PTR_FIRST_ELEM:%.*]] = getelementptr ptr, ptr [[ELEM_ARRAY_PTR]], i32 0
// LLVM: [[PTR_FIRST_ELEM:%.*]] = getelementptr inbounds 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: [[INIT_START_FLD_PTR:%.*]] = getelementptr inbounds %"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: [[INIT_END_FLD_PTR:%.*]] = getelementptr %"class.std::initializer_list<const char *>", ptr [[INIT_STRUCT]], i32 0, i32 1
// LLVM: [[ELEM_ARRAY_END:%.*]] = getelementptr inbounds ptr, ptr [[PTR_FIRST_ELEM]], i64 2
// LLVM: [[INIT_END_FLD_PTR:%.*]] = getelementptr inbounds %"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
// LLVM: call void @_ZSt1fIPKcEvSt16initializer_listIT_E(%"class.std::initializer_list<const char *>" [[ARG2PASS]])
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 {{.*}}
10 changes: 5 additions & 5 deletions clang/test/CIR/CodeGen/var-arg-float.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ double f1(int n, ...) {
// LLVM: [[RETP:%.*]] = alloca double, i64 1, align 8
// LLVM: [[RESP:%.*]] = alloca double, i64 1, align 8
// LLVM: call void @llvm.va_start.p0(ptr [[VARLIST:%.*]])
// LLVM: [[VR_OFFS_P:%.*]] = getelementptr %struct.__va_list, ptr [[VARLIST]], i32 0, i32 4
// LLVM: [[VR_OFFS_P:%.*]] = getelementptr inbounds %struct.__va_list, ptr [[VARLIST]], i32 0, i32 4
// LLVM: [[VR_OFFS:%.*]] = load i32, ptr [[VR_OFFS_P]], align 4
// LLVM-NEXT: [[CMP0:%.*]] = icmp sge i32 [[VR_OFFS]], 0
// LLVM-NEXT: br i1 [[CMP0]], label %[[BB_ON_STACK:.*]], label %[[BB_MAY_REG:.*]]
Expand All @@ -94,16 +94,16 @@ double f1(int n, ...) {
// LLVM-NEXT: br i1 [[CMP1]], label %[[BB_IN_REG:.*]], label %[[BB_ON_STACK]]

// LLVM: [[BB_IN_REG]]: ;
// LLVM-NEXT: [[VR_TOP_P:%.*]] = getelementptr %struct.__va_list, ptr [[VARLIST]], i32 0, i32 2
// LLVM-NEXT: [[VR_TOP_P:%.*]] = getelementptr inbounds %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_P:%.*]] = getelementptr inbounds %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
10 changes: 5 additions & 5 deletions clang/test/CIR/CodeGen/var-arg-scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void f1(__builtin_va_list c) {
// LLVM: br label %[[SCOPE_FRONT:.*]]

// LLVM: [[SCOPE_FRONT]]: ; preds = %1
// LLVM: [[GR_OFFS_P:%.*]] = getelementptr %struct.__va_list, ptr [[VARLIST]], i32 0, i32 3
// LLVM: [[GR_OFFS_P:%.*]] = getelementptr inbounds %struct.__va_list, ptr [[VARLIST]], i32 0, i32 3
// LLVM: [[GR_OFFS:%.*]] = load i32, ptr [[GR_OFFS_P]], align 4
// LLVM-NEXT: [[CMP0:%.*]] = icmp sge i32 [[GR_OFFS]], 0
// LLVM-NEXT: br i1 [[CMP0]], label %[[BB_ON_STACK:.*]], label %[[BB_MAY_REG:.*]]
Expand All @@ -83,16 +83,16 @@ void f1(__builtin_va_list c) {
// LLVM-NEXT: br i1 [[CMP1]], label %[[BB_IN_REG:.*]], label %[[BB_ON_STACK]]

// LLVM: [[BB_IN_REG]]: ;
// LLVM-NEXT: [[GR_TOP_P:%.*]] = getelementptr %struct.__va_list, ptr [[VARLIST]], i32 0, i32 1
// LLVM-NEXT: [[GR_TOP_P:%.*]] = getelementptr inbounds %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_P:%.*]] = getelementptr inbounds %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
10 changes: 5 additions & 5 deletions clang/test/CIR/CodeGen/var-arg.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int f1(int n, ...) {
// LLVM: [[RETP:%.*]] = alloca i32, i64 1, align 4
// LLVM: [[RESP:%.*]] = alloca i32, i64 1, align 4
// LLVM: call void @llvm.va_start.p0(ptr [[VARLIST:%.*]])
// LLVM: [[GR_OFFS_P:%.*]] = getelementptr %struct.__va_list, ptr [[VARLIST]], i32 0, i32 3
// LLVM: [[GR_OFFS_P:%.*]] = getelementptr inbounds %struct.__va_list, ptr [[VARLIST]], i32 0, i32 3
// LLVM: [[GR_OFFS:%.*]] = load i32, ptr [[GR_OFFS_P]], align 4
// LLVM-NEXT: [[CMP0:%.*]] = icmp sge i32 [[GR_OFFS]], 0
// LLVM-NEXT: br i1 [[CMP0]], label %[[BB_ON_STACK:.*]], label %[[BB_MAY_REG:.*]]
Expand All @@ -97,16 +97,16 @@ int f1(int n, ...) {
// LLVM-NEXT: br i1 [[CMP1]], label %[[BB_IN_REG:.*]], label %[[BB_ON_STACK]]

// LLVM: [[BB_IN_REG]]: ;
// LLVM-NEXT: [[GR_TOP_P:%.*]] = getelementptr %struct.__va_list, ptr [[VARLIST]], i32 0, i32 1
// LLVM-NEXT: [[GR_TOP_P:%.*]] = getelementptr inbounds %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_P:%.*]] = getelementptr inbounds %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: }
}
Loading

0 comments on commit d9b7c41

Please sign in to comment.