[SimplifyCFG] add a struct to house optional folds (PR34603)
authorSanjay Patel <spatel@rotateright.com>
Wed, 27 Sep 2017 14:54:16 +0000 (14:54 +0000)
committerSanjay Patel <spatel@rotateright.com>
Wed, 27 Sep 2017 14:54:16 +0000 (14:54 +0000)
commit0f9b4773c1c68886e63161cd78f4d576db632eb8
tree9de4bf36027a572bb21daaee4ca08eb1b6fe1a04
parent3ec848bc50b46d0583689cd83f4da4b1d23690cf
[SimplifyCFG] add a struct to house optional folds (PR34603)

This was intended to be no-functional-change, but it's not - there's a test diff.

So I thought I should stop here and post it as-is to see if this looks like what was expected
based on the discussion in PR34603:
https://bugs.llvm.org/show_bug.cgi?id=34603

Notes:
 1. The test improvement occurs because the existing 'LateSimplifyCFG' marker is not carried
    through the recursive calls to 'SimplifyCFG()->SimplifyCFGOpt().run()->SimplifyCFG()'.
    The parameter isn't passed down, so we pick up the default value from the function signature
    after the first level. I assumed that was a bug, so I've passed 'Options' down in all of the
    'SimplifyCFG' calls.

 2. I split 'LateSimplifyCFG' into 2 bits: ConvertSwitchToLookupTable and KeepCanonicalLoops.
    This would theoretically allow us to differentiate the transforms controlled by those params
    independently.

 3. We could stash the optional AssumptionCache pointer and 'LoopHeaders' pointer in the struct too.
    I just stopped here to minimize the diffs.

 4. Similarly, I stopped short of messing with the pass manager layer. I have another question that
    could wait for the follow-up: why is the new pass manager creating the pass with LateSimplifyCFG
    set to true no matter where in the pipeline it's creating SimplifyCFG passes?

    // Create an early function pass manager to cleanup the output of the
    // frontend.
    EarlyFPM.addPass(SimplifyCFGPass());

    -->

    /// \brief Construct a pass with the default thresholds
    /// and switch optimizations.
    SimplifyCFGPass::SimplifyCFGPass()
       : BonusInstThreshold(UserBonusInstThreshold),
         LateSimplifyCFG(true) {}   <-- switches get converted to lookup tables and loops may not be in canonical form

    If this is unintended, then it's possible that the current behavior of dropping the 'LateSimplifyCFG'
    setting via recursion was masking this bug.

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

llvm-svn: 314308
llvm/include/llvm/Transforms/Scalar/SimplifyCFG.h
llvm/include/llvm/Transforms/Utils/Local.h
llvm/lib/CodeGen/DwarfEHPrepare.cpp
llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll
llvm/tools/bugpoint/CrashDebugger.cpp