diff options
author | Arthur Eubanks <aeubanks@google.com> | 2021-08-27 12:32:59 -0700 |
---|---|---|
committer | Arthur Eubanks <aeubanks@google.com> | 2021-09-22 09:52:37 -0700 |
commit | e7249e4acf3cf9438d6d9e02edecebd5b622a4dc (patch) | |
tree | b5fefa07dfe12636cccedcf8970ba6b4b07f0f46 /llvm/lib/Transforms/Utils/SimplifyCFG.cpp | |
parent | 32a50078657dd8beead327a3478ede4e9d730432 (diff) | |
download | llvm-e7249e4acf3cf9438d6d9e02edecebd5b622a4dc.zip llvm-e7249e4acf3cf9438d6d9e02edecebd5b622a4dc.tar.gz llvm-e7249e4acf3cf9438d6d9e02edecebd5b622a4dc.tar.bz2 |
[SimplifyCFG] Ignore free instructions when computing cost for folding branch to common dest
When determining whether to fold branches to a common destination by
merging two blocks, SimplifyCFG will count the number of instructions to
be moved into the first basic block. However, there's no reason to count
free instructions like bitcasts and other similar instructions.
This resolves missed branch foldings with -fstrict-vtable-pointers in
llvm-test-suite's lambda benchmark.
Reviewed By: spatel
Differential Revision: https://reviews.llvm.org/D108837
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 2ff98b2..a3bd89e 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -3258,13 +3258,16 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, DomTreeUpdater *DTU, SawVectorOp |= isVectorOp(I); // Account for the cost of duplicating this instruction into each - // predecessor. - NumBonusInsts += PredCount; - - // Early exits once we reach the limit. - if (NumBonusInsts > - BonusInstThreshold * BranchFoldToCommonDestVectorMultiplier) - return false; + // predecessor. Ignore free instructions. + if (!TTI || + TTI->getUserCost(&I, CostKind) != TargetTransformInfo::TCC_Free) { + NumBonusInsts += PredCount; + + // Early exits once we reach the limit. + if (NumBonusInsts > + BonusInstThreshold * BranchFoldToCommonDestVectorMultiplier) + return false; + } auto IsBCSSAUse = [BB, &I](Use &U) { auto *UI = cast<Instruction>(U.getUser()); |