llvm-project/llvm/lib/CodeGen
Craig Topper a37df84f99 [SelectionDAG][RISCV] Remove code for handling too small shift type from SimplifyDemandedBits.
This code detected that the type returned from getShiftAmountTy was
too small to hold the constant shift amount. But it used the full
type size instead of scalar type size leading it to crash for
scalable vectors.

This code was necessary when getShiftAmountTy would always
return the target preferred shift amount type for scalars even when
the type was an illegal type larger than the target supported. For
vectors, getShiftAmountTy has always returned the vector type.

Fortunately, getShiftAmountTy was fixed a while ago to detect that
the target's preferred size for scalars is not large enough for the
type. So we can delete this code.

Switched to use getShiftAmountConstant to further simplify the code.

Fixs PR61561.
2023-03-21 11:08:19 -07:00
..
AsmPrinter [WebAssembly] Support debug info for TLS + global in PIC mode 2023-03-17 20:16:48 -07:00
GlobalISel CodeGen: Reorder case handling for is.fpclass legalization 2023-03-17 11:29:50 -04:00
LiveDebugValues [llvm] Use *{Map,Set}::contains (NFC) 2023-03-15 18:06:32 -07:00
MIRParser Use APInt::getSignificantBits instead of APInt::getMinSignedBits (NFC) 2023-02-19 23:56:52 -08:00
SelectionDAG [SelectionDAG][RISCV] Remove code for handling too small shift type from SimplifyDemandedBits. 2023-03-21 11:08:19 -07:00
AggressiveAntiDepBreaker.cpp
AggressiveAntiDepBreaker.h
AllocationOrder.cpp
AllocationOrder.h
Analysis.cpp
AssignmentTrackingAnalysis.cpp [Assignment Tracking][NFC] Use BitVectors as masks for SmallVectors 2023-03-21 09:11:54 +00:00
AtomicExpandPass.cpp
BasicBlockSections.cpp Move global namespace cl::opt inside llvm:: 2023-02-14 00:09:44 -08:00
BasicBlockSectionsProfileReader.cpp
BasicTargetTransformInfo.cpp
BranchFolding.cpp
BranchFolding.h
BranchRelaxation.cpp
BreakFalseDeps.cpp
CalcSpillWeights.cpp
CallBrPrepare.cpp [CodeGen] Fix warnings 2023-02-16 20:08:35 -08:00
CallingConvLower.cpp
CFGuardLongjmp.cpp
CFIFixup.cpp
CFIInstrInserter.cpp
CMakeLists.txt [llvm] boilerplate for new callbrprepare codegen IR pass 2023-02-16 17:58:33 -08:00
CodeGen.cpp [llvm] boilerplate for new callbrprepare codegen IR pass 2023-02-16 17:58:33 -08:00
CodeGenCommonISel.cpp [NFC] Make FPClassTest a bitmask enumeration 2023-02-24 15:12:16 +07:00
CodeGenPassBuilder.cpp
CodeGenPrepare.cpp [llvm] Use *{Map,Set}::contains (NFC) 2023-03-15 18:06:32 -07:00
CommandFlags.cpp Remove -lower-global-dtors-via-cxa-atexit flag 2023-03-14 14:18:11 -07:00
ComplexDeinterleavingPass.cpp [Codegen][ARM][AArch64] Support symmetric operations on complex numbers 2023-03-14 12:11:10 +00:00
CriticalAntiDepBreaker.cpp
CriticalAntiDepBreaker.h
DeadMachineInstructionElim.cpp
DetectDeadLanes.cpp
DFAPacketizer.cpp [NFC] Fix incorrect comment in VLIW packetizer 2023-03-01 21:19:06 +08:00
DwarfEHPrepare.cpp Recommit DwarfEHPrepare: insert extra unwind paths for stack protector to instrument 2023-03-16 13:43:17 +00:00
EarlyIfConversion.cpp [MachineTraceMetrics][NFC] Move Strategy enum out of the class 2023-02-14 16:38:47 +03:00
EdgeBundles.cpp
EHContGuardCatchret.cpp
ExecutionDomainFix.cpp
ExpandLargeDivRem.cpp
ExpandLargeFpConvert.cpp
ExpandMemCmp.cpp
ExpandPostRAPseudos.cpp
ExpandReductions.cpp
ExpandVectorPredication.cpp
FaultMaps.cpp
FEntryInserter.cpp
FinalizeISel.cpp
FixupStatepointCallerSaved.cpp Use *{Map,Set}::contains (NFC) 2023-03-15 08:46:32 -07:00
FuncletLayout.cpp
GCMetadata.cpp
GCMetadataPrinter.cpp
GCRootLowering.cpp
GlobalMerge.cpp
HardwareLoops.cpp
IfConversion.cpp
ImplicitNullChecks.cpp
IndirectBrExpandPass.cpp
InlineSpiller.cpp [CodeGen] Use *{Set,Map}::contains (NFC) 2023-03-14 08:07:42 -07:00
InterferenceCache.cpp
InterferenceCache.h
InterleavedAccessPass.cpp [RISCV][NFC] Share interleave mask checking logic 2023-03-14 11:02:52 +00:00
InterleavedLoadCombinePass.cpp Use APInt::count{l,r}_{zero,one} (NFC) 2023-02-19 22:04:47 -08:00
IntrinsicLowering.cpp
JMCInstrumenter.cpp
LatencyPriorityQueue.cpp
LazyMachineBlockFrequencyInfo.cpp
LexicalScopes.cpp
LiveDebugVariables.cpp
LiveDebugVariables.h
LiveInterval.cpp
LiveIntervalCalc.cpp
LiveIntervals.cpp
LiveIntervalUnion.cpp
LivePhysRegs.cpp
LiveRangeCalc.cpp
LiveRangeEdit.cpp LiveRangeEdit: Use Register 2023-03-17 17:34:52 -04:00
LiveRangeShrink.cpp
LiveRangeUtils.h
LiveRegMatrix.cpp
LiveRegUnits.cpp
LiveStacks.cpp
LiveVariables.cpp
LLVMTargetMachine.cpp
LocalStackSlotAllocation.cpp
LoopTraversal.cpp
LowerEmuTLS.cpp
LowLevelType.cpp [AArch64][SME2] Add CodeGen support for target("aarch64.svcount"). 2023-03-02 12:07:41 +00:00
MachineBasicBlock.cpp
MachineBlockFrequencyInfo.cpp
MachineBlockPlacement.cpp [CodeGen] Use *{Set,Map}::contains (NFC) 2023-03-14 08:07:42 -07:00
MachineBranchProbabilityInfo.cpp
MachineCFGPrinter.cpp
MachineCheckDebugify.cpp
MachineCombiner.cpp [MachineCombiner] Support local strategy for traces 2023-02-17 13:17:22 +03:00
MachineCopyPropagation.cpp
MachineCSE.cpp
MachineCycleAnalysis.cpp
MachineDebugify.cpp
MachineDominanceFrontier.cpp
MachineDominators.cpp
MachineFrameInfo.cpp
MachineFunction.cpp [llvm] Use *{Map,Set}::contains (NFC) 2023-03-15 18:06:32 -07:00
MachineFunctionPass.cpp
MachineFunctionPrinterPass.cpp
MachineFunctionSplitter.cpp
MachineInstr.cpp
MachineInstrBundle.cpp
MachineLateInstrsCleanup.cpp
MachineLICM.cpp [CodeGen] Use *{Set,Map}::contains (NFC) 2023-03-14 08:07:42 -07:00
MachineLoopInfo.cpp
MachineLoopUtils.cpp
MachineModuleInfo.cpp [MC][nfc] Don't use a value after it has been std::move()'d 2023-02-23 15:15:24 -05:00
MachineModuleInfoImpls.cpp
MachineModuleSlotTracker.cpp
MachineOperand.cpp [IR] Add operator<< overload for CmpInst::Predicate (NFC) 2023-03-07 15:10:56 +01:00
MachineOptimizationRemarkEmitter.cpp
MachineOutliner.cpp [NFC][Outliner] Delete default ctors for Candidate & OutlinedFunction. 2023-03-20 11:17:10 -07:00
MachinePassManager.cpp [PassManager] Run PassInstrumentation after analysis invalidation 2023-03-15 08:36:14 -07:00
MachinePipeliner.cpp
MachinePostDominators.cpp
MachineRegionInfo.cpp
MachineRegisterInfo.cpp
MachineScheduler.cpp
MachineSink.cpp
MachineSizeOpts.cpp
MachineSSAContext.cpp [llvm][Uniformity] A phi with an undef argument is not always divergent 2023-02-20 14:26:43 +05:30
MachineSSAUpdater.cpp
MachineStableHash.cpp
MachineStripDebug.cpp
MachineTraceMetrics.cpp [MachineTraceMetrics] Add local strategy 2023-02-15 15:53:14 +03:00
MachineUniformityAnalysis.cpp [AMDGPU] Use UniformityAnalysis in AtomicOptimizer 2023-03-15 09:39:55 +01:00
MachineVerifier.cpp [llvm] add CallBrPrepare pass to pipelines 2023-02-16 17:58:34 -08:00
MacroFusion.cpp
MBFIWrapper.cpp
MIRCanonicalizerPass.cpp
MIRFSDiscriminator.cpp [FSAFDO] Improve FS discriminator encoding 2023-03-09 23:18:48 -08:00
MIRNamerPass.cpp
MIRPrinter.cpp
MIRPrintingPass.cpp
MIRSampleProfile.cpp [FSAFDO] Improve FS discriminator encoding 2023-03-09 23:18:48 -08:00
MIRVRegNamerUtils.cpp [CodeGen] Use *{Set,Map}::contains (NFC) 2023-03-14 08:07:42 -07:00
MIRVRegNamerUtils.h
MIRYamlMapping.cpp
MLRegallocEvictAdvisor.cpp Move global namespace cl::opt inside llvm:: 2023-02-14 00:09:44 -08:00
MLRegallocEvictAdvisor.h
MLRegallocPriorityAdvisor.cpp
ModuloSchedule.cpp
MultiHazardRecognizer.cpp
NonRelocatableStringpool.cpp
OptimizePHIs.cpp
ParallelCG.cpp
PatchableFunction.cpp
PeepholeOptimizer.cpp
PHIElimination.cpp
PHIEliminationUtils.cpp
PHIEliminationUtils.h
PostRAHazardRecognizer.cpp
PostRASchedulerList.cpp
PreISelIntrinsicLowering.cpp
ProcessImplicitDefs.cpp
PrologEpilogInserter.cpp
PseudoProbeInserter.cpp [FSAFDO] Improve FS discriminator encoding 2023-03-09 23:18:48 -08:00
PseudoSourceValue.cpp
RDFGraph.cpp
RDFLiveness.cpp
RDFRegisters.cpp
ReachingDefAnalysis.cpp
README.txt
RegAllocBase.cpp
RegAllocBase.h
RegAllocBasic.cpp
RegAllocEvictionAdvisor.cpp Move global namespace cl::opt inside llvm:: 2023-02-14 00:09:44 -08:00
RegAllocEvictionAdvisor.h
RegAllocFast.cpp [RegAllocFast] insert additional spills along indirect edges of INLINEASM_BR 2023-03-01 15:21:11 -08:00
RegAllocGreedy.cpp RegAllocGreedy: Don't use Register reference 2023-03-17 15:22:13 -04:00
RegAllocGreedy.h
RegAllocPBQP.cpp
RegAllocPriorityAdvisor.cpp
RegAllocPriorityAdvisor.h
RegAllocScore.cpp
RegAllocScore.h
RegisterBank.cpp
RegisterBankInfo.cpp
RegisterClassInfo.cpp
RegisterCoalescer.cpp
RegisterCoalescer.h
RegisterPressure.cpp
RegisterScavenging.cpp
RegisterUsageInfo.cpp
RegUsageInfoCollector.cpp
RegUsageInfoPropagate.cpp
RemoveRedundantDebugValues.cpp
RenameIndependentSubregs.cpp
ReplaceWithVeclib.cpp
ResetMachineFunctionPass.cpp
SafeStack.cpp
SafeStackLayout.cpp
SafeStackLayout.h
SanitizerBinaryMetadata.cpp
ScheduleDAG.cpp
ScheduleDAGInstrs.cpp [CodeGen] Use LLVM_ATTRIBUTE_UNUSED instead of LLVM_DUMP_METHOD on a raw_ostream operator<<. 2023-02-27 18:12:18 -08:00
ScheduleDAGPrinter.cpp
ScoreboardHazardRecognizer.cpp
SelectOptimize.cpp
ShadowStackGCLowering.cpp
ShrinkWrap.cpp
SjLjEHPrepare.cpp
SlotIndexes.cpp [CodeGen] Use *{Set,Map}::contains (NFC) 2023-03-14 08:07:42 -07:00
SpillPlacement.cpp
SpillPlacement.h
SplitKit.cpp
SplitKit.h
StackColoring.cpp
StackFrameLayoutAnalysisPass.cpp
StackMapLivenessAnalysis.cpp
StackMaps.cpp
StackProtector.cpp StackProtector: expose RequiresStackProtector publicly. NFC. 2023-03-16 11:32:45 +00:00
StackSlotColoring.cpp
SwiftErrorValueTracking.cpp
SwitchLoweringUtils.cpp
TailDuplication.cpp
TailDuplicator.cpp
TargetFrameLoweringImpl.cpp
TargetInstrInfo.cpp [MachineCombiner] Preserve debug instruction number 2023-03-13 09:29:30 -04:00
TargetLoweringBase.cpp [CodeGen] Always expand division larger than i128 2023-03-01 15:33:45 +01:00
TargetLoweringObjectFileImpl.cpp Remove -lower-global-dtors-via-cxa-atexit flag 2023-03-14 14:18:11 -07:00
TargetOptionsImpl.cpp
TargetPassConfig.cpp Remove -lower-global-dtors-via-cxa-atexit flag 2023-03-14 14:18:11 -07:00
TargetRegisterInfo.cpp
TargetSchedule.cpp
TargetSubtargetInfo.cpp
TwoAddressInstructionPass.cpp
TypePromotion.cpp [TypePromotion] Deference pointer before printing it in a debug message. 2023-03-02 23:43:36 -08:00
UnreachableBlockElim.cpp
ValueTypes.cpp [SPIR-V] Add Machine Value Type for SPIR-V builtins 2023-03-20 23:15:34 +01:00
VirtRegMap.cpp
VLIWMachineScheduler.cpp
WasmEHPrepare.cpp
WinEHPrepare.cpp
XRayInstrumentation.cpp

//===---------------------------------------------------------------------===//

Common register allocation / spilling problem:

        mul lr, r4, lr
        str lr, [sp, #+52]
        ldr lr, [r1, #+32]
        sxth r3, r3
        ldr r4, [sp, #+52]
        mla r4, r3, lr, r4

can be:

        mul lr, r4, lr
        mov r4, lr
        str lr, [sp, #+52]
        ldr lr, [r1, #+32]
        sxth r3, r3
        mla r4, r3, lr, r4

and then "merge" mul and mov:

        mul r4, r4, lr
        str r4, [sp, #+52]
        ldr lr, [r1, #+32]
        sxth r3, r3
        mla r4, r3, lr, r4

It also increase the likelihood the store may become dead.

//===---------------------------------------------------------------------===//

bb27 ...
        ...
        %reg1037 = ADDri %reg1039, 1
        %reg1038 = ADDrs %reg1032, %reg1039, %noreg, 10
    Successors according to CFG: 0x8b03bf0 (#5)

bb76 (0x8b03bf0, LLVM BB @0x8b032d0, ID#5):
    Predecessors according to CFG: 0x8b0c5f0 (#3) 0x8b0a7c0 (#4)
        %reg1039 = PHI %reg1070, mbb<bb76.outer,0x8b0c5f0>, %reg1037, mbb<bb27,0x8b0a7c0>

Note ADDri is not a two-address instruction. However, its result %reg1037 is an
operand of the PHI node in bb76 and its operand %reg1039 is the result of the
PHI node. We should treat it as a two-address code and make sure the ADDri is
scheduled after any node that reads %reg1039.

//===---------------------------------------------------------------------===//

Use local info (i.e. register scavenger) to assign it a free register to allow
reuse:
        ldr r3, [sp, #+4]
        add r3, r3, #3
        ldr r2, [sp, #+8]
        add r2, r2, #2
        ldr r1, [sp, #+4]  <==
        add r1, r1, #1
        ldr r0, [sp, #+4]
        add r0, r0, #2

//===---------------------------------------------------------------------===//

LLVM aggressively lift CSE out of loop. Sometimes this can be negative side-
effects:

R1 = X + 4
R2 = X + 7
R3 = X + 15

loop:
load [i + R1]
...
load [i + R2]
...
load [i + R3]

Suppose there is high register pressure, R1, R2, R3, can be spilled. We need
to implement proper re-materialization to handle this:

R1 = X + 4
R2 = X + 7
R3 = X + 15

loop:
R1 = X + 4  @ re-materialized
load [i + R1]
...
R2 = X + 7 @ re-materialized
load [i + R2]
...
R3 = X + 15 @ re-materialized
load [i + R3]

Furthermore, with re-association, we can enable sharing:

R1 = X + 4
R2 = X + 7
R3 = X + 15

loop:
T = i + X
load [T + 4]
...
load [T + 7]
...
load [T + 15]
//===---------------------------------------------------------------------===//

It's not always a good idea to choose rematerialization over spilling. If all
the load / store instructions would be folded then spilling is cheaper because
it won't require new live intervals / registers. See 2003-05-31-LongShifts for
an example.

//===---------------------------------------------------------------------===//

With a copying garbage collector, derived pointers must not be retained across
collector safe points; the collector could move the objects and invalidate the
derived pointer. This is bad enough in the first place, but safe points can
crop up unpredictably. Consider:

        %array = load { i32, [0 x %obj] }** %array_addr
        %nth_el = getelementptr { i32, [0 x %obj] }* %array, i32 0, i32 %n
        %old = load %obj** %nth_el
        %z = div i64 %x, %y
        store %obj* %new, %obj** %nth_el

If the i64 division is lowered to a libcall, then a safe point will (must)
appear for the call site. If a collection occurs, %array and %nth_el no longer
point into the correct object.

The fix for this is to copy address calculations so that dependent pointers
are never live across safe point boundaries. But the loads cannot be copied
like this if there was an intervening store, so may be hard to get right.

Only a concurrent mutator can trigger a collection at the libcall safe point.
So single-threaded programs do not have this requirement, even with a copying
collector. Still, LLVM optimizations would probably undo a front-end's careful
work.

//===---------------------------------------------------------------------===//

The ocaml frametable structure supports liveness information. It would be good
to support it.

//===---------------------------------------------------------------------===//

The FIXME in ComputeCommonTailLength in BranchFolding.cpp needs to be
revisited. The check is there to work around a misuse of directives in inline
assembly.

//===---------------------------------------------------------------------===//

It would be good to detect collector/target compatibility instead of silently
doing the wrong thing.

//===---------------------------------------------------------------------===//

It would be really nice to be able to write patterns in .td files for copies,
which would eliminate a bunch of explicit predicates on them (e.g. no side
effects).  Once this is in place, it would be even better to have tblgen
synthesize the various copy insertion/inspection methods in TargetInstrInfo.

//===---------------------------------------------------------------------===//

Stack coloring improvements:

1. Do proper LiveStacks analysis on all stack objects including those which are
   not spill slots.
2. Reorder objects to fill in gaps between objects.
   e.g. 4, 1, <gap>, 4, 1, 1, 1, <gap>, 4 => 4, 1, 1, 1, 1, 4, 4

//===---------------------------------------------------------------------===//

The scheduler should be able to sort nearby instructions by their address. For
example, in an expanded memset sequence it's not uncommon to see code like this:

  movl $0, 4(%rdi)
  movl $0, 8(%rdi)
  movl $0, 12(%rdi)
  movl $0, 0(%rdi)

Each of the stores is independent, and the scheduler is currently making an
arbitrary decision about the order.

//===---------------------------------------------------------------------===//

Another opportunitiy in this code is that the $0 could be moved to a register:

  movl $0, 4(%rdi)
  movl $0, 8(%rdi)
  movl $0, 12(%rdi)
  movl $0, 0(%rdi)

This would save substantial code size, especially for longer sequences like
this. It would be easy to have a rule telling isel to avoid matching MOV32mi
if the immediate has more than some fixed number of uses. It's more involved
to teach the register allocator how to do late folding to recover from
excessive register pressure.