llvm-project/llvm/lib/Transforms/Scalar
Craig Topper 25067f179f [LoopIdiomRecognize] Teach detectShiftUntilZeroIdiom to recognize loops where the counter is decrementing.
This adds support for loops like

unsigned clz(unsigned x) {
    unsigned w = sizeof (x) * CHAR_BIT;
    while (x) {
        w--;
        x >>= 1;
    }

    return w;
}

and

unsigned clz(unsigned x) {
    unsigned w = sizeof (x) * CHAR_BIT - 1;
    while (x >>= 1) {
        w--;
    }

    return w;
}

To support these we look for add x, -1 as well as add x, 1 that
we already matched. If the value was -1 we need to subtract from
the initial counter value instead of adding to it.

Fixes PR48404.

Differential Revision: https://reviews.llvm.org/D92745
2020-12-14 14:25:05 -08:00
..
ADCE.cpp [ADCE] Use succ_empty (NFC) 2020-11-15 19:52:59 -08:00
AlignmentFromAssumptions.cpp Reland [AssumeBundles] Use operand bundles to encode alignment assumptions 2020-09-12 15:36:06 +02:00
AnnotationRemarks.cpp Add !annotation metadata and remarks pass. 2020-11-13 13:24:10 +00:00
BDCE.cpp [BDCE] SExt -> ZExt when no sign bits is used and instruction has multiple uses 2020-07-10 08:34:53 +01:00
CMakeLists.txt [ScalarizeMaskedMemIntrinsic] Move from CodeGen into Transforms 2020-12-08 12:25:58 -05:00
CallSiteSplitting.cpp [Support] Introduce a new InstructionCost class 2020-12-11 08:12:54 +00:00
ConstantHoisting.cpp [Scalar] ConstantHoistingPass - iterate with const references. NFCI. 2020-09-24 18:40:50 +01:00
ConstraintElimination.cpp [ConstraintElimination] Handle constraints with all zero var coeffs. 2020-12-05 12:06:53 +00:00
CorrelatedValuePropagation.cpp [CVP] Simplify and generalize switch handling 2020-12-12 21:12:27 +01:00
DCE.cpp [DCE] Always get TargetLibraryInfo 2020-11-17 20:41:05 -08:00
DeadStoreElimination.cpp [DSE][NFC] Need to be carefull mixing signed and unsigned types 2020-12-08 16:53:37 +07:00
DivRemPairs.cpp [ValueTracking] Use assume's noundef operand bundle 2020-10-14 20:16:33 +09:00
EarlyCSE.cpp [EarlyCSE] delete abs/nabs handling 2020-11-10 21:10:58 -05:00
FlattenCFGPass.cpp
Float2Int.cpp [Float2Int] Stop passing around a reference to the class member Roots. NFC 2020-04-16 15:24:13 +02:00
GVN.cpp [Transforms] Use llvm::is_contained (NFC) 2020-11-18 20:42:22 -08:00
GVNHoist.cpp [Transforms] Use llvm::is_contained (NFC) 2020-11-18 20:42:22 -08:00
GVNSink.cpp Use llvm::is_contained where appropriate (NFC) 2020-07-27 10:20:44 -07:00
GuardWidening.cpp
IVUsersPrinter.cpp
IndVarSimplify.cpp [IndVarSimplify] Fix Modified status when handling dead PHI nodes 2020-11-26 14:28:21 +01:00
InductiveRangeCheckElimination.cpp [IRCE] Remove unused IsSigned and its accessor (NFC) 2020-12-04 21:26:12 -08:00
InferAddressSpaces.cpp [InferAddrSpace] Teach to handle assumed address space. 2020-11-16 17:06:33 -05:00
InstSimplifyPass.cpp [Bindings] Move LLVMAddInstructionSimplifyPass to Scalar.cpp 2020-09-02 10:35:39 -07:00
JumpThreading.cpp [JumpThreading] Call eraseBlock when folding a conditional branch 2020-12-03 23:50:17 -08:00
LICM.cpp [LICM][docs] Document that LICM is also a canonicalization transform. NFC. 2020-12-08 11:56:35 +00:00
LoopAccessAnalysisPrinter.cpp
LoopDataPrefetch.cpp [LoopInfo] empty() -> isInnermost(), add isOutermost() 2020-09-22 23:28:51 +03:00
LoopDeletion.cpp Revert "[LoopDeletion] Allows deletion of possibly infinite side-effect free loops" 2020-11-07 00:32:12 -05:00
LoopDistribute.cpp [LAA] Relax restrictions on early exits in loop structure 2020-12-14 12:44:01 -08:00
LoopFlatten.cpp [LoopFlatten] Widen IV, support ZExt. 2020-11-23 08:57:19 +00:00
LoopFuse.cpp [Loop Fusion] Use pred_empty and succ_empty (NFC) 2020-11-15 20:32:57 -08:00
LoopIdiomRecognize.cpp [LoopIdiomRecognize] Teach detectShiftUntilZeroIdiom to recognize loops where the counter is decrementing. 2020-12-14 14:25:05 -08:00
LoopInstSimplify.cpp
LoopInterchange.cpp [SCEV] Use isa<> pattern for testing for CouldNotCompute [NFC] 2020-11-24 18:47:49 -08:00
LoopLoadElimination.cpp [LAA] Relax restrictions on early exits in loop structure 2020-12-14 12:44:01 -08:00
LoopPassManager.cpp [NewPM] Make pass adaptors less templatey 2020-12-04 08:30:50 -08:00
LoopPredication.cpp [NFC][SCEV] Refactor monotonic predicate checks to return enums instead of bools 2020-10-29 16:01:25 +07:00
LoopRerollPass.cpp [LoopReroll][NewPM] Port -loop-reroll to NPM 2020-09-25 12:09:06 -07:00
LoopRotation.cpp [NFC] Reduce include files dependency. 2020-12-03 18:25:05 +03:00
LoopSimplifyCFG.cpp [LoopInfo] empty() -> isInnermost(), add isOutermost() 2020-09-22 23:28:51 +03:00
LoopSink.cpp Reland: Expand existing loopsink testing to also test loopsinking using new pass manager and fix LICM bug. 2020-11-20 10:26:33 -05:00
LoopStrengthReduce.cpp Reland [DebugInfo] Improve dbg preservation in LSR. 2020-12-14 16:15:18 +01:00
LoopUnrollAndJamPass.cpp [LoopUnrollAndJam] Allow unroll and jam loops forced by user. 2020-09-17 19:40:14 +00:00
LoopUnrollPass.cpp [NFC] fix some typos in LoopUnrollPass 2020-10-17 14:20:55 +01:00
LoopUnswitch.cpp [Transforms] Use llvm::erase_value (NFC) 2020-12-13 09:48:47 -08:00
LoopVersioningLICM.cpp [SCEV] Use isa<> pattern for testing for CouldNotCompute [NFC] 2020-11-24 18:47:49 -08:00
LowerAtomic.cpp
LowerConstantIntrinsics.cpp [Transforms] Use pred_empty (NFC) 2020-11-16 22:09:14 -08:00
LowerExpectIntrinsic.cpp Revert "clang-misexpect: Profile Guided Validation of Performance Annotations in LLVM" 2020-11-14 13:12:38 +03:00
LowerGuardIntrinsic.cpp
LowerMatrixIntrinsics.cpp Port -lower-matrix-intrinsics-minimal to NPM 2020-11-19 17:42:48 -08:00
LowerWidenableCondition.cpp
MakeGuardsExplicit.cpp
MemCpyOptimizer.cpp [MemCpyOpt] Port to MemorySSA 2020-12-01 17:57:41 +01:00
MergeICmps.cpp [MergeICmps] Fix missing split. 2020-12-01 16:50:55 +01:00
MergedLoadStoreMotion.cpp
NaryReassociate.cpp [NFC][NARY-REASSOCIATE] Restructure code to aviod isPotentiallyReassociatable 2020-12-04 16:19:43 +07:00
NewGVN.cpp [Transforms] Delete unused declarations from NewGVN/CoroSplit/ValueMapper 2020-12-06 13:04:01 -08:00
PartiallyInlineLibCalls.cpp
PlaceSafepoints.cpp static const char *const foo => const char foo[] 2020-12-01 10:33:18 -08:00
Reassociate.cpp [NFC][Reassociate] Delay checking isLoadCombineCandidate() until after ShouldConvertOrWithNoCommonBitsToAdd() but before haveNoCommonBitsSet() 2020-11-18 23:57:12 +03:00
Reg2Mem.cpp [Reg2Mem] add support for the new pass manager 2020-11-08 11:14:05 +00:00
RewriteStatepointsForGC.cpp GC-parseable element atomic memcpy/memmove 2020-10-23 14:06:09 -07:00
SCCP.cpp [SCCP] Handle bitcast of vector constants. 2020-11-03 12:58:39 +00:00
SROA.cpp [SROA] Pass Twine by const reference. NFCI. 2020-10-30 11:36:58 +00:00
Scalar.cpp [ScalarizeMaskedMemIntrin] Add new PM support 2020-12-08 17:15:22 -05:00
ScalarizeMaskedMemIntrin.cpp [ScalarizeMaskedMemIntrin] Add new PM support 2020-12-08 17:15:22 -05:00
Scalarizer.cpp [Scalarizer] Avoid changing name of non-instructions 2020-09-15 14:15:50 +02:00
SeparateConstOffsetFromGEP.cpp [NewPM] Port -separate-const-offset-from-gep 2020-11-09 17:42:36 -08:00
SimpleLoopUnswitch.cpp [LoopInfo] empty() -> isInnermost(), add isOutermost() 2020-09-22 23:28:51 +03:00
SimplifyCFGPass.cpp [SimplifyCFG] Respect optforfuzzing in NPM pass 2020-11-16 09:56:37 -08:00
Sink.cpp Sink: Handle instruction sink when a user is dead 2020-10-09 16:20:26 -07:00
SpeculateAroundPHIs.cpp [NFC][CostModel] Add TargetCostKind to relevant APIs 2020-05-05 10:35:54 +01:00
SpeculativeExecution.cpp SpeculativeExecution: Allow speculating more instruction types 2020-11-18 17:00:19 +01:00
StraightLineStrengthReduce.cpp [NPM] Port -slsr to NPM 2020-10-27 09:21:40 +08:00
StructurizeCFG.cpp static const char *const foo => const char foo[] 2020-12-01 10:33:18 -08:00
TailRecursionElimination.cpp [CSSPGO] IR intrinsic for pseudo-probe block instrumentation 2020-11-20 10:39:24 -08:00
WarnMissedTransforms.cpp [SVE] Add support for scalable vectors with vectorize.scalable.enable loop attribute 2020-12-02 13:23:43 +00:00