[llvm-branch-commits] [misexpect] Support diagnostics from frontend profile data (PR #96524)

2024-06-24 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-pgo

@llvm/pr-subscribers-llvm-transforms

Author: Paul Kirth (ilovepi)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/96524.diff


3 Files Affected:

- (modified) llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp (+18) 
- (modified) llvm/lib/Transforms/Utils/MisExpect.cpp (+1-2) 
- (modified) llvm/test/Transforms/PGOProfile/missing-annotation.ll (+1-1) 


``diff
diff --git a/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp 
b/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
index 17c5a4ee1fd0b..4075749d0d574 100644
--- a/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
+++ b/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
@@ -369,9 +369,21 @@ static bool lowerExpectIntrinsic(Function ) {
 if (BranchInst *BI = dyn_cast(BB.getTerminator())) {
   if (handleBranchExpect(*BI))
 ExpectIntrinsicsHandled++;
+  else {
+SmallVector Weights;
+if (extractBranchWeights(*BI, Weights))
+  misexpect::checkMissingAnnotations(*BI, Weights,
+ /*IsFrontendInstr=*/false);
+  }
 } else if (SwitchInst *SI = dyn_cast(BB.getTerminator())) {
   if (handleSwitchExpect(*SI))
 ExpectIntrinsicsHandled++;
+  else {
+SmallVector Weights;
+if (extractBranchWeights(*SI, Weights))
+  misexpect::checkMissingAnnotations(*SI, Weights,
+ /*isFrontend=*/false);
+  }
 }
 
 // Remove llvm.expect intrinsics. Iterate backwards in order
@@ -383,6 +395,12 @@ static bool lowerExpectIntrinsic(Function ) {
 if (SelectInst *SI = dyn_cast()) {
   if (handleBrSelExpect(*SI))
 ExpectIntrinsicsHandled++;
+  else {
+SmallVector Weights;
+if (extractBranchWeights(*SI, Weights))
+  misexpect::checkMissingAnnotations(*SI, Weights,
+ /*isFrontend=*/false);
+  }
 }
 continue;
   }
diff --git a/llvm/lib/Transforms/Utils/MisExpect.cpp 
b/llvm/lib/Transforms/Utils/MisExpect.cpp
index 933d9a146533d..1d88f867971e8 100644
--- a/llvm/lib/Transforms/Utils/MisExpect.cpp
+++ b/llvm/lib/Transforms/Utils/MisExpect.cpp
@@ -302,8 +302,7 @@ void checkMissingAnnotations(Instruction ,
 return;
 
   if (IsFrontendInstr) {
-// TODO: Frontend checking will have to be thought through, since we need
-// to do the check on branches that don't have expect intrinsics
+verifyMissingAnnotations(I, ExistingWeights);
   } else {
 SmallVector ExpectedWeights;
 if (extractBranchWeights(I, ExpectedWeights))
diff --git a/llvm/test/Transforms/PGOProfile/missing-annotation.ll 
b/llvm/test/Transforms/PGOProfile/missing-annotation.ll
index 6b52302449900..03b0b3bb5cc54 100644
--- a/llvm/test/Transforms/PGOProfile/missing-annotation.ll
+++ b/llvm/test/Transforms/PGOProfile/missing-annotation.ll
@@ -3,7 +3,7 @@
 
 ; RUN: llvm-profdata merge %S/Inputs/misexpect-branch-correct.proftext -o 
%t.profdata
 
-; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" 
-pgo-test-profile-file=%t.profdata -pgo-missing-annotations 
-pass-remarks=missing-annotation -S 2>&1 | FileCheck %s 
--check-prefix=MISSING_ANNOTATION
+; RUN: opt < %s -passes="function(lower-expect),pgo-instr-use" 
-pgo-test-profile-file=%t.profdata -pgo-missing-annotations 
-pass-remarks=missing-annotations -S 2>&1 | FileCheck %s 
--check-prefix=MISSING_ANNOTATION
 
 ; MISSING_ANNOTATION: remark: misexpect-branch.c:22:0:  Extremely hot 
condition. Consider adding llvm.expect intrinsic
 

``




https://github.com/llvm/llvm-project/pull/96524
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [misexpect] Support diagnostics from frontend profile data (PR #96524)

2024-06-24 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi created 
https://github.com/llvm/llvm-project/pull/96524

None


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits