[PATCH] D89917: Revert "SimplifyCFG: Clean up optforfuzzing implementation"

Zequan Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 21 17:14:10 PDT 2020


zequanwu created this revision.
zequanwu added a reviewer: arsenm.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
zequanwu requested review of this revision.
Herald added a subscriber: wdng.

In commit cdd006eec9409923f9a56b9026ce2cb72e7b71dc <https://reviews.llvm.org/rGcdd006eec9409923f9a56b9026ce2cb72e7b71dc>, the options `SimplifyCondBranch` and `FoldTwoEntryPHINode` were added and set to false when attribute `OptForFuzzing` is present. We also need to do the same for `SimplifyCFGPass` which is NPM version of `CFGSimplifyPass`. It will be duplicated. We can just check for the attribute at `simplifyCondBranch` and `FoldTwoEntryPHINode`
See discussion: https://reviews.llvm.org/D89590
This reverts commit cdd006eec9409923f9a56b9026ce2cb72e7b71dc <https://reviews.llvm.org/rGcdd006eec9409923f9a56b9026ce2cb72e7b71dc>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89917

Files:
  llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp


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,8 @@
 
 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))
     return false;
 
   // Conditional branch
@@ -6270,13 +6274,11 @@
 
   IRBuilder<> Builder(BB);
 
-  if (Options.FoldTwoEntryPHINode) {
-    // If there is a trivial two-entry PHI node in this basic block, and we can
-    // eliminate it, do so now.
-    if (auto *PN = dyn_cast<PHINode>(BB->begin()))
-      if (PN->getNumIncomingValues() == 2)
-        Changed |= FoldTwoEntryPHINode(PN, TTI, DL);
-  }
+  // If there is a trivial two-entry PHI node in this basic block, and we can
+  // eliminate it, do so now.
+  if (auto *PN = dyn_cast<PHINode>(BB->begin()))
+    if (PN->getNumIncomingValues() == 2)
+      Changed |= FoldTwoEntryPHINode(PN, TTI, DL);
 
   Instruction *Terminator = BB->getTerminator();
   Builder.SetInsertPoint(Terminator);
Index: llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
+++ llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
@@ -273,14 +273,6 @@
       return false;
 
     Options.AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
-    if (F.hasFnAttribute(Attribute::OptForFuzzing)) {
-      Options.setSimplifyCondBranch(false)
-             .setFoldTwoEntryPHINode(false);
-    } else {
-      Options.setSimplifyCondBranch(true)
-             .setFoldTwoEntryPHINode(true);
-    }
-
     auto &TTI = getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
     return simplifyFunctionCFG(F, TTI, Options);
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89917.299828.patch
Type: text/x-patch
Size: 2393 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201022/e8a1ec77/attachment.bin>


More information about the llvm-commits mailing list