[SanitizerCoverage] Avoid unnecessary inttoptr
We are indexing into an array here, so we can use CreateConstInBoundsGEP2_64 instead of the manual arithmetic. Reviewed By: vitalybuka Pull Request: https://github.com/llvm/llvm-project/pull/119097
This commit is contained in:
committed by
GitHub
parent
b6c22a4e58
commit
4646cabf01
@@ -1045,10 +1045,8 @@ void ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
|
||||
->setCannotMerge(); // gets the PC using GET_CALLER_PC.
|
||||
}
|
||||
if (Options.TracePCGuard) {
|
||||
auto GuardPtr = IRB.CreateIntToPtr(
|
||||
IRB.CreateAdd(IRB.CreatePointerCast(FunctionGuardArray, IntptrTy),
|
||||
ConstantInt::get(IntptrTy, Idx * 4)),
|
||||
PtrTy);
|
||||
auto GuardPtr = IRB.CreateConstInBoundsGEP2_64(
|
||||
FunctionGuardArray->getValueType(), FunctionGuardArray, 0, Idx);
|
||||
if (Options.GatedCallbacks) {
|
||||
Instruction *I = &*IP;
|
||||
auto GateBranch = CreateGateBranch(F, FunctionGateCmp, I);
|
||||
|
||||
@@ -7,13 +7,14 @@ target triple = "i386-unknown-linux-gnu"
|
||||
define i32 @foo() #0 {
|
||||
; CHECK-LABEL: define i32 @foo() comdat {
|
||||
; CHECK-NEXT: entry:
|
||||
; CHECK-NEXT: call void @__sanitizer_cov_trace_pc_guard(ptr inttoptr (i32 ptrtoint (ptr @__sancov_gen_ to i32) to ptr)) #[[ATTR1:[0-9]+]]
|
||||
; CHECK-NEXT: call void @__sanitizer_cov_trace_pc_guard(ptr @__sancov_gen_) #[[ATTR1:[0-9]+]]
|
||||
; CHECK-NEXT: ret i32 0
|
||||
;
|
||||
entry:
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
; UTC_ARGS: --disable
|
||||
; CHECK-DAG: declare void @__sanitizer_cov_trace_pc_indir(i32)
|
||||
; CHECK-DAG: declare void @__sanitizer_cov_trace_cmp1(i8 zeroext, i8 zeroext)
|
||||
; CHECK-DAG: declare void @__sanitizer_cov_trace_cmp2(i16 zeroext, i16 zeroext)
|
||||
|
||||
@@ -12,7 +12,7 @@ define i32 @with_dbg(ptr %a, ptr %b) !dbg !3 {
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP1]], 42
|
||||
; CHECK-NEXT: br i1 [[CMP]], label %[[BB0:.*]], label %[[BB1:.*]]
|
||||
; CHECK: [[BB0]]:
|
||||
; CHECK-NEXT: call void @__sanitizer_cov_trace_pc_guard(ptr inttoptr (i64 add (i64 ptrtoint (ptr @__sancov_gen_ to i64), i64 4) to ptr)) #[[ATTR1]], !dbg [[DBG7:![0-9]+]]
|
||||
; CHECK-NEXT: call void @__sanitizer_cov_trace_pc_guard(ptr getelementptr inbounds ([2 x i32], ptr @__sancov_gen_, i64 0, i64 1)) #[[ATTR1]], !dbg [[DBG7:![0-9]+]]
|
||||
; CHECK-NEXT: store i32 [[TMP1]], ptr [[B]], align 4
|
||||
; CHECK-NEXT: br label %[[BB1]]
|
||||
; CHECK: [[BB1]]:
|
||||
@@ -38,7 +38,7 @@ define i32 @without_dbg(ptr %a, ptr %b) {
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP1]], 42
|
||||
; CHECK-NEXT: br i1 [[CMP]], label %[[BB0:.*]], label %[[BB1:.*]]
|
||||
; CHECK: [[BB0]]:
|
||||
; CHECK-NEXT: call void @__sanitizer_cov_trace_pc_guard(ptr inttoptr (i64 add (i64 ptrtoint (ptr @__sancov_gen_.1 to i64), i64 4) to ptr)) #[[ATTR1]]
|
||||
; CHECK-NEXT: call void @__sanitizer_cov_trace_pc_guard(ptr getelementptr inbounds ([2 x i32], ptr @__sancov_gen_.1, i64 0, i64 1)) #[[ATTR1]]
|
||||
; CHECK-NEXT: store i32 [[TMP1]], ptr [[B]], align 4
|
||||
; CHECK-NEXT: br label %[[BB1]]
|
||||
; CHECK: [[BB1]]:
|
||||
|
||||
Reference in New Issue
Block a user