[llvm] 6539a80 - [CSSPGO] Avoid deleting probe instruction in FoldValueComparisonIntoPredecessors

via llvm-commits llvm-commits at lists.llvm.org
Wed May 19 13:39:44 PDT 2021


Author: wlei
Date: 2021-05-19T13:39:05-07:00
New Revision: 6539a80bc9e8a8587a199e10caa843b40e2f2c71

URL: https://github.com/llvm/llvm-project/commit/6539a80bc9e8a8587a199e10caa843b40e2f2c71
DIFF: https://github.com/llvm/llvm-project/commit/6539a80bc9e8a8587a199e10caa843b40e2f2c71.diff

LOG: [CSSPGO] Avoid deleting probe instruction in FoldValueComparisonIntoPredecessors

This change tries to fix a place missing `moveAndDanglePseudoProbes `. In FoldValueComparisonIntoPredecessors, it folds the BB into predecessors and then marked the BB unreachable. However, the original logic from the BB is still alive, deleting the probe will mislead the SampleLoader mark it as zero count sample.

Reviewed By: hoy, wenlei

Differential Revision: https://reviews.llvm.org/D102721

Added: 
    llvm/test/Transforms/SampleProfile/pseudo-probe-dangle3.ll

Modified: 
    llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index e25362c346d63..a4a7555c9b27a 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1325,6 +1325,10 @@ bool SimplifyCFGOpt::PerformValueComparisonIntoPredecessorFolding(
     DTU->applyUpdates(Updates);
   }
 
+  // Here the BB is not a dead block but folded into its predecessors, so move
+  // the probe and mark it as dangling.
+  moveAndDanglePseudoProbes(BB, NewSI);
+
   ++NumFoldValueComparisonIntoPredecessors;
   return true;
 }

diff  --git a/llvm/test/Transforms/SampleProfile/pseudo-probe-dangle3.ll b/llvm/test/Transforms/SampleProfile/pseudo-probe-dangle3.ll
new file mode 100644
index 0000000000000..ae6aaa8f08bdd
--- /dev/null
+++ b/llvm/test/Transforms/SampleProfile/pseudo-probe-dangle3.ll
@@ -0,0 +1,37 @@
+; Test after FoldValueComparisonIntoPredecessors, one dangling probe is generated
+; RUN: opt -S -passes='pseudo-probe,simplifycfg' < %s | FileCheck %s
+
+
+; CHECK: if.end80:                                         ; preds = %if.end
+; CHECK-NEXT:   call void @llvm.pseudoprobe(i64 -2281696412744416103, i64 3, i32 0, i64 -1)
+; CHECK-NEXT:   call void @llvm.pseudoprobe(i64 -2281696412744416103, i64 4, i32 2, i64 -1)
+
+define dso_local i32 @readCBPandCoeffsFromNAL(i1 %c, i32 %x, i32 %y) local_unnamed_addr {
+;
+if.end:
+  br i1 %c, label %if.end80, label %if.then64
+
+if.then64:                                        ; preds = %if.end
+  ret i32 %y
+
+if.end80:                                         ; preds = %if.end
+  switch i32 %x, label %lor.lhs.false89 [
+  i32 10, label %if.end172237
+  i32 14, label %if.end172237
+  i32 9, label %if.end172
+  ]
+
+lor.lhs.false89:                                  ; preds = %lor.lhs.false89, %if.end80
+  %cmp91 = icmp eq i32 %x, 12
+  br i1 %cmp91, label %if.end172, label %lor.lhs.false89
+
+if.end172:                                        ; preds = %lor.lhs.false89, %if.end80
+  br label %if.end239
+
+if.end172237:                                     ; preds = %if.end80, %if.end80
+  br label %if.end239
+
+if.end239:                                        ; preds = %if.end172237, %if.end172
+  %cbp.0 = phi i32 [ 1, %if.end172237 ], [ 0, %if.end172 ]
+  ret i32 %cbp.0
+}


        


More information about the llvm-commits mailing list