[clang] cc53707 - LLVMInstrumentation: Simplify mcdc.tvbitmap.update with GEP.
NAKAMURA Takumi via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 24 19:14:46 PST 2024
Author: NAKAMURA Takumi
Date: 2024-02-25T11:21:46+09:00
New Revision: cc53707a5c104eb7789829ecdb2e3ae2be1a42da
URL: https://github.com/llvm/llvm-project/commit/cc53707a5c104eb7789829ecdb2e3ae2be1a42da
DIFF: https://github.com/llvm/llvm-project/commit/cc53707a5c104eb7789829ecdb2e3ae2be1a42da.diff
LOG: LLVMInstrumentation: Simplify mcdc.tvbitmap.update with GEP.
Added:
Modified:
clang/test/Profile/c-mcdc-class.cpp
clang/test/Profile/c-mcdc-logicalop-ternary.c
clang/test/Profile/c-mcdc-nested-ternary.c
clang/test/Profile/c-mcdc-not.c
clang/test/Profile/c-mcdc.c
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
llvm/test/Instrumentation/InstrProfiling/mcdc.ll
Removed:
################################################################################
diff --git a/clang/test/Profile/c-mcdc-class.cpp b/clang/test/Profile/c-mcdc-class.cpp
index 2206a39ee4ffb4..6aab55add32807 100644
--- a/clang/test/Profile/c-mcdc-class.cpp
+++ b/clang/test/Profile/c-mcdc-class.cpp
@@ -54,9 +54,7 @@ Value::~Value(void) {
// UPDATE FINAL BITMASK WITH RESULT.
// MCDCCTOR-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
// MCDCCTOR: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
-// MCDCCTOR: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
-// MCDCCTOR: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm__ZN5ValueC2Ev to i64), %[[LAB2]]
-// MCDCCTOR: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
+// MCDCCTOR: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm__ZN5ValueC2Ev, i32 %[[LAB1]]
// MCDCCTOR: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
// MCDCCTOR: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
// MCDCCTOR: %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
@@ -93,9 +91,7 @@ Value::~Value(void) {
// UPDATE FINAL BITMASK WITH RESULT.
// MCDCDTOR-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
// MCDCDTOR: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
-// MCDCDTOR: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
-// MCDCDTOR: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm__ZN5ValueD2Ev to i64), %[[LAB2]]
-// MCDCDTOR: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
+// MCDCDTOR: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm__ZN5ValueD2Ev, i32 %[[LAB1]]
// MCDCDTOR: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
// MCDCDTOR: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
// MCDCDTOR: %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
diff --git a/clang/test/Profile/c-mcdc-logicalop-ternary.c b/clang/test/Profile/c-mcdc-logicalop-ternary.c
index 558643f422021c..3e6b6b1e380d1e 100644
--- a/clang/test/Profile/c-mcdc-logicalop-ternary.c
+++ b/clang/test/Profile/c-mcdc-logicalop-ternary.c
@@ -20,9 +20,7 @@ int test(int a, int b, int c, int d, int e, int f) {
// MCDC-LABEL: cond.true:
// MCDC-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
// MCDC: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
-// MCDC: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
-// MCDC: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm_test to i64), %[[LAB2]]
-// MCDC: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
+// MCDC: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm_test, i32 %[[LAB1]]
// MCDC: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
// MCDC: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
// 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) {
// MCDC-LABEL: land.end:
// MCDC-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
// MCDC: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
-// MCDC: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
-// MCDC: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr getelementptr inbounds ([3 x i8], ptr @__profbm_test, i32 0, i32 1) to i64), %[[LAB2]]
-// MCDC: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
+// MCDC: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr getelementptr inbounds ([3 x i8], ptr @__profbm_test, i32 0, i32 1), i32 %[[LAB1]]
// MCDC: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
// MCDC: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
// 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) {
// MCDC-LABEL: cond.false:
// MCDC-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
// MCDC: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
-// MCDC: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
-// MCDC: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm_test to i64), %[[LAB2]]
-// MCDC: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
+// MCDC: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm_test, i32 %[[LAB1]]
// MCDC: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
// MCDC: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
// 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) {
// MCDC-LABEL: lor.end:
// MCDC-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
// MCDC: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
-// MCDC: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
-// MCDC: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr getelementptr inbounds ([3 x i8], ptr @__profbm_test, i32 0, i32 2) to i64), %[[LAB2]]
-// MCDC: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
+// MCDC: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr getelementptr inbounds ([3 x i8], ptr @__profbm_test, i32 0, i32 2), i32 %[[LAB1]]
// MCDC: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
// MCDC: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
// MCDC: %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
diff --git a/clang/test/Profile/c-mcdc-nested-ternary.c b/clang/test/Profile/c-mcdc-nested-ternary.c
index 4b014e07f6df53..ebea17ca146ae6 100644
--- a/clang/test/Profile/c-mcdc-nested-ternary.c
+++ b/clang/test/Profile/c-mcdc-nested-ternary.c
@@ -57,9 +57,7 @@ int test(int b, int c, int d, int e, int f) {
// UPDATE FINAL BITMASK WITH RESULT.
// MCDC-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
// MCDC: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
-// MCDC: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
-// MCDC: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm_test to i64), %[[LAB2]]
-// MCDC: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
+// MCDC: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm_test, i32 %[[LAB1]]
// MCDC: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
// MCDC: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
// MCDC: %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
diff --git a/clang/test/Profile/c-mcdc-not.c b/clang/test/Profile/c-mcdc-not.c
index aa638b9680b841..165bfbae3349da 100644
--- a/clang/test/Profile/c-mcdc-not.c
+++ b/clang/test/Profile/c-mcdc-not.c
@@ -77,9 +77,7 @@ int test(int a, int b, int c, int d, int e, int f) {
// UPDATE FINAL BITMASK WITH RESULT.
// MCDC-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
// MCDC: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
-// MCDC: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
-// MCDC: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm_test to i64), %[[LAB2]]
-// MCDC: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
+// MCDC: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm_test, i32 %[[LAB1]]
// MCDC: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
// MCDC: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
// MCDC: %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
diff --git a/clang/test/Profile/c-mcdc.c b/clang/test/Profile/c-mcdc.c
index ac845d204853db..823160329b31f8 100644
--- a/clang/test/Profile/c-mcdc.c
+++ b/clang/test/Profile/c-mcdc.c
@@ -91,9 +91,7 @@ int test(int a, int b, int c, int d, int e, int f) {
// NOPROFPASS: call void @llvm.instrprof.mcdc.tvbitmap.update(ptr @__profn_test, i64 [[HASH]], i32 8, i32 0, ptr %mcdc.addr)
// MCDC-DAG: %[[TEMP:mcdc.temp[0-9]*]] = load i32, ptr %mcdc.addr, align 4
// MCDC: %[[LAB1:[0-9]+]] = lshr i32 %[[TEMP]], 3
-// MCDC: %[[LAB2:[0-9]+]] = zext i32 %[[LAB1]] to i64
-// MCDC: %[[LAB3:[0-9]+]] = add i64 ptrtoint (ptr @__profbm_test to i64), %[[LAB2]]
-// MCDC: %[[LAB4:[0-9]+]] = inttoptr i64 %[[LAB3]] to ptr
+// MCDC: %[[LAB4:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm_test, i32 %[[LAB1]]
// MCDC: %[[LAB5:[0-9]+]] = and i32 %[[TEMP]], 7
// MCDC: %[[LAB6:[0-9]+]] = trunc i32 %[[LAB5]] to i8
// MCDC: %[[LAB7:[0-9]+]] = shl i8 1, %[[LAB6]]
diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
index a19b1408725441..dbd44bd36e1148 100644
--- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -969,9 +969,7 @@ void InstrLowerer::lowerMCDCTestVectorBitmapUpdate(
InstrProfMCDCTVBitmapUpdate *Update) {
IRBuilder<> Builder(Update);
auto *Int8Ty = Type::getInt8Ty(M.getContext());
- auto *Int8PtrTy = PointerType::getUnqual(M.getContext());
auto *Int32Ty = Type::getInt32Ty(M.getContext());
- auto *Int64Ty = Type::getInt64Ty(M.getContext());
auto *MCDCCondBitmapAddr = Update->getMCDCCondBitmapAddr();
auto *BitmapAddr = getBitmapAddress(Update);
@@ -984,15 +982,9 @@ void InstrLowerer::lowerMCDCTestVectorBitmapUpdate(
auto *BitmapByteOffset = Builder.CreateLShr(Temp, 0x3);
// Add byte offset to section base byte address.
- // %2 = zext i32 %1 to i64
- // %3 = add i64 ptrtoint (ptr @__profbm_test to i64), %2
+ // %4 = getelementptr inbounds i8, ptr @__profbm_test, i32 %1
auto *BitmapByteAddr =
- Builder.CreateAdd(Builder.CreatePtrToInt(BitmapAddr, Int64Ty),
- Builder.CreateZExtOrBitCast(BitmapByteOffset, Int64Ty));
-
- // Convert to a pointer.
- // %4 = inttoptr i32 %3 to ptr
- BitmapByteAddr = Builder.CreateIntToPtr(BitmapByteAddr, Int8PtrTy);
+ Builder.CreateInBoundsPtrAdd(BitmapAddr, BitmapByteOffset);
// Calculate bit offset into bitmap byte by using div8 remainder (AND ~8)
// %5 = and i32 %mcdc.temp, 7
diff --git a/llvm/test/Instrumentation/InstrProfiling/mcdc.ll b/llvm/test/Instrumentation/InstrProfiling/mcdc.ll
index f61f6ca136ce77..a7f1e606e35fa0 100644
--- a/llvm/test/Instrumentation/InstrProfiling/mcdc.ll
+++ b/llvm/test/Instrumentation/InstrProfiling/mcdc.ll
@@ -32,9 +32,7 @@ entry:
call void @llvm.instrprof.mcdc.tvbitmap.update(ptr @__profn_test, i64 99278, i32 1, i32 0, ptr %mcdc.addr)
; CHECK: %[[TEMP:mcdc.*]] = load i32, ptr %mcdc.addr, align 4
; CHECK-NEXT: %[[LAB4:[0-9]+]] = lshr i32 %[[TEMP]], 3
- ; CHECK-NEXT: %[[LAB5:[0-9]+]] = zext i32 %[[LAB4]] to i64
- ; CHECK-NEXT: %[[LAB6:[0-9]+]] = add i64 ptrtoint (ptr @__profbm_test to i64), %[[LAB5]]
- ; CHECK-NEXT: %[[LAB7:[0-9]+]] = inttoptr i64 %[[LAB6]] to ptr
+ ; CHECK-NEXT: %[[LAB7:[0-9]+]] = getelementptr inbounds i8, ptr @__profbm_test, i32 %[[LAB4]]
; CHECK-NEXT: %[[LAB8:[0-9]+]] = and i32 %[[TEMP]], 7
; CHECK-NEXT: %[[LAB9:[0-9]+]] = trunc i32 %[[LAB8]] to i8
; CHECK-NEXT: %[[LAB10:[0-9]+]] = shl i8 1, %[[LAB9]]
More information about the cfe-commits
mailing list