Skip to content

Commit cc53707

Browse files
committed
LLVMInstrumentation: Simplify mcdc.tvbitmap.update with GEP.
1 parent 7b9504f commit cc53707

File tree

7 files changed

+12
-40
lines changed

7 files changed

+12
-40
lines changed

clang/test/Profile/c-mcdc-class.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ Value::~Value(void) {
5454
// UPDATE FINAL BITMASK WITH RESULT.
5555
// MCDCCTOR-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
5656
// MCDCCTOR: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
57-
// MCDCCTOR: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
58-
// MCDCCTOR: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm__ZN5ValueC2Ev to i64), %[[LAB2]]
59-
// MCDCCTOR: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
57+
// MCDCCTOR: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm__ZN5ValueC2Ev, i32 %[[LAB1]]
6058
// MCDCCTOR: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
6159
// MCDCCTOR: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
6260
// MCDCCTOR: %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
@@ -93,9 +91,7 @@ Value::~Value(void) {
9391
// UPDATE FINAL BITMASK WITH RESULT.
9492
// MCDCDTOR-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
9593
// MCDCDTOR: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
96-
// MCDCDTOR: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
97-
// MCDCDTOR: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm__ZN5ValueD2Ev to i64), %[[LAB2]]
98-
// MCDCDTOR: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
94+
// MCDCDTOR: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm__ZN5ValueD2Ev, i32 %[[LAB1]]
9995
// MCDCDTOR: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
10096
// MCDCDTOR: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
10197
// MCDCDTOR: %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]

clang/test/Profile/c-mcdc-logicalop-ternary.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ int test(int a, int b, int c, int d, int e, int f) {
2020
// MCDC-LABEL: cond.true:
2121
// MCDC-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
2222
// MCDC: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
23-
// MCDC: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
24-
// MCDC: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm_test to i64), %[[LAB2]]
25-
// MCDC: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
23+
// MCDC: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm_test, i32 %[[LAB1]]
2624
// MCDC: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
2725
// MCDC: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
2826
// MCDC: %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
@@ -38,9 +36,7 @@ int test(int a, int b, int c, int d, int e, int f) {
3836
// MCDC-LABEL: land.end:
3937
// MCDC-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
4038
// MCDC: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
41-
// MCDC: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
42-
// MCDC: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr getelementptr inbounds ([3 x i8], ptr @__profbm_test, i32 0, i32 1) to i64), %[[LAB2]]
43-
// MCDC: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
39+
// MCDC: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr getelementptr inbounds ([3 x i8], ptr @__profbm_test, i32 0, i32 1), i32 %[[LAB1]]
4440
// MCDC: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
4541
// MCDC: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
4642
// MCDC: %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
@@ -52,9 +48,7 @@ int test(int a, int b, int c, int d, int e, int f) {
5248
// MCDC-LABEL: cond.false:
5349
// MCDC-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
5450
// MCDC: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
55-
// MCDC: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
56-
// MCDC: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm_test to i64), %[[LAB2]]
57-
// MCDC: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
51+
// MCDC: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm_test, i32 %[[LAB1]]
5852
// MCDC: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
5953
// MCDC: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
6054
// MCDC: %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
@@ -70,9 +64,7 @@ int test(int a, int b, int c, int d, int e, int f) {
7064
// MCDC-LABEL: lor.end:
7165
// MCDC-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
7266
// MCDC: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
73-
// MCDC: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
74-
// MCDC: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr getelementptr inbounds ([3 x i8], ptr @__profbm_test, i32 0, i32 2) to i64), %[[LAB2]]
75-
// MCDC: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
67+
// MCDC: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr getelementptr inbounds ([3 x i8], ptr @__profbm_test, i32 0, i32 2), i32 %[[LAB1]]
7668
// MCDC: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
7769
// MCDC: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
7870
// MCDC: %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]

clang/test/Profile/c-mcdc-nested-ternary.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ int test(int b, int c, int d, int e, int f) {
5757
// UPDATE FINAL BITMASK WITH RESULT.
5858
// MCDC-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
5959
// MCDC: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
60-
// MCDC: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
61-
// MCDC: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm_test to i64), %[[LAB2]]
62-
// MCDC: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
60+
// MCDC: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm_test, i32 %[[LAB1]]
6361
// MCDC: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
6462
// MCDC: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
6563
// MCDC: %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]

clang/test/Profile/c-mcdc-not.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ int test(int a, int b, int c, int d, int e, int f) {
7777
// UPDATE FINAL BITMASK WITH RESULT.
7878
// MCDC-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
7979
// MCDC: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
80-
// MCDC: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
81-
// MCDC: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm_test to i64), %[[LAB2]]
82-
// MCDC: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
80+
// MCDC: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm_test, i32 %[[LAB1]]
8381
// MCDC: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
8482
// MCDC: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
8583
// MCDC: %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]

clang/test/Profile/c-mcdc.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ int test(int a, int b, int c, int d, int e, int f) {
9191
// NOPROFPASS: call void @llvm.instrprof.mcdc.tvbitmap.update(ptr @__profn_test, i64 [[HASH]], i32 8, i32 0, ptr %mcdc.addr)
9292
// MCDC-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
9393
// MCDC: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
94-
// MCDC: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
95-
// MCDC: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm_test to i64), %[[LAB2]]
96-
// MCDC: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
94+
// MCDC: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm_test, i32 %[[LAB1]]
9795
// MCDC: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
9896
// MCDC: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
9997
// MCDC: %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]

llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -969,9 +969,7 @@ void InstrLowerer::lowerMCDCTestVectorBitmapUpdate(
969969
InstrProfMCDCTVBitmapUpdate *Update) {
970970
IRBuilder<> Builder(Update);
971971
auto *Int8Ty = Type::getInt8Ty(M.getContext());
972-
auto *Int8PtrTy = PointerType::getUnqual(M.getContext());
973972
auto *Int32Ty = Type::getInt32Ty(M.getContext());
974-
auto *Int64Ty = Type::getInt64Ty(M.getContext());
975973
auto *MCDCCondBitmapAddr = Update->getMCDCCondBitmapAddr();
976974
auto *BitmapAddr = getBitmapAddress(Update);
977975

@@ -984,15 +982,9 @@ void InstrLowerer::lowerMCDCTestVectorBitmapUpdate(
984982
auto *BitmapByteOffset = Builder.CreateLShr(Temp, 0x3);
985983

986984
// Add byte offset to section base byte address.
987-
// %2 = zext i32 %1 to i64
988-
// %3 = add i64 ptrtoint (ptr @__profbm_test to i64), %2
985+
// %4 = getelementptr inbounds i8, ptr @__profbm_test, i32 %1
989986
auto *BitmapByteAddr =
990-
Builder.CreateAdd(Builder.CreatePtrToInt(BitmapAddr, Int64Ty),
991-
Builder.CreateZExtOrBitCast(BitmapByteOffset, Int64Ty));
992-
993-
// Convert to a pointer.
994-
// %4 = inttoptr i32 %3 to ptr
995-
BitmapByteAddr = Builder.CreateIntToPtr(BitmapByteAddr, Int8PtrTy);
987+
Builder.CreateInBoundsPtrAdd(BitmapAddr, BitmapByteOffset);
996988

997989
// Calculate bit offset into bitmap byte by using div8 remainder (AND ~8)
998990
// %5 = and i32 %mcdc.temp, 7

llvm/test/Instrumentation/InstrProfiling/mcdc.ll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ entry:
3232
call void @llvm.instrprof.mcdc.tvbitmap.update(ptr @__profn_test, i64 99278, i32 1, i32 0, ptr %mcdc.addr)
3333
; CHECK: %[[TEMP:mcdc.*]] = load i32, ptr %mcdc.addr, align 4
3434
; CHECK-NEXT: %[[LAB4:[0-9]+]] = lshr i32 %[[TEMP]], 3
35-
; CHECK-NEXT: %[[LAB5:[0-9]+]] = zext i32 %[[LAB4]] to i64
36-
; CHECK-NEXT: %[[LAB6:[0-9]+]] = add i64 ptrtoint (ptr @__profbm_test to i64), %[[LAB5]]
37-
; CHECK-NEXT: %[[LAB7:[0-9]+]] = inttoptr i64 %[[LAB6]] to ptr
35+
; CHECK-NEXT: %[[LAB7:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm_test, i32 %[[LAB4]]
3836
; CHECK-NEXT: %[[LAB8:[0-9]+]] = and i32 %[[TEMP]], 7
3937
; CHECK-NEXT: %[[LAB9:[0-9]+]] = trunc i32 %[[LAB8]] to i8
4038
; CHECK-NEXT: %[[LAB10:[0-9]+]] = shl i8 1, %[[LAB9]]

0 commit comments

Comments
 (0)