[PATCH] D89590: [NPM][SimplifyCFGPass] For OptForFuzzing attribute, disable SimplifyCondBranch and FoldTwoEntryPHINode in NPM

Zequan Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 20 17:08:56 PDT 2020


zequanwu updated this revision to Diff 299520.
zequanwu added a comment.

address comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89590/new/

https://reviews.llvm.org/D89590

Files:
  llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/Transforms/SimplifyCFG/opt-for-fuzzing.ll


Index: llvm/test/Transforms/SimplifyCFG/opt-for-fuzzing.ll
===================================================================
--- llvm/test/Transforms/SimplifyCFG/opt-for-fuzzing.ll
+++ llvm/test/Transforms/SimplifyCFG/opt-for-fuzzing.ll
@@ -1,4 +1,5 @@
 ; RUN: opt < %s -simplifycfg -S | FileCheck %s
+; RUN: opt < %s -passes=simplifycfg -S | FileCheck %s
 
 define i32 @foo(i32 %x) optforfuzzing {
 entry:
Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -2415,6 +2415,9 @@
   // dependence information for this check, but simplifycfg can't keep it up
   // to date, and this catches most of the cases we care about anyway.
   BasicBlock *BB = PN->getParent();
+  const Function *Fn = BB->getParent();
+  if (Fn && Fn->hasFnAttribute(Attribute::OptForFuzzing))
+    return false;
 
   BasicBlock *IfTrue, *IfFalse;
   Value *IfCond = GetIfCondition(BB, IfTrue, IfFalse);
@@ -6055,7 +6058,9 @@
 
 bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
   BasicBlock *BB = BI->getParent();
-  if (!Options.SimplifyCondBranch)
+  const Function *Fn = BB->getParent();
+  if (Fn && Fn->hasFnAttribute(Attribute::OptForFuzzing) &&
+      !Options.SimplifyCondBranch)
     return false;
 
   // Conditional branch
Index: llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
+++ llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
@@ -245,6 +245,10 @@
                                        FunctionAnalysisManager &AM) {
   auto &TTI = AM.getResult<TargetIRAnalysis>(F);
   Options.AC = &AM.getResult<AssumptionAnalysis>(F);
+  if (F.hasFnAttribute(Attribute::OptForFuzzing))
+    Options.setSimplifyCondBranch(false).setFoldTwoEntryPHINode(false);
+  else
+    Options.setSimplifyCondBranch(true).setFoldTwoEntryPHINode(true);
   if (!simplifyFunctionCFG(F, TTI, Options))
     return PreservedAnalyses::all();
   PreservedAnalyses PA;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89590.299520.patch
Type: text/x-patch
Size: 2131 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201021/70b6275d/attachment.bin>


More information about the llvm-commits mailing list