llvm-project/llvm/lib/Target/BPF
Yonghong Song a0841dfe85 [BPF] Fix a bug in peephole optimization
One of current peephole optimiations is to remove SLL/SRL if
the sub register has been zero extended. This phase has two bugs
and one limitations.

First, for the physical subregister used in pseudo insn COPY
like below, it permits incorrect optimization.
    %0:gpr32 = COPY $w0
    ...
    %4:gpr = MOV_32_64 %0:gpr32
    %5:gpr = SLL_ri %4:gpr(tied-def 0), 32
    %6:gpr = SRA_ri %5:gpr(tied-def 0), 32
The $w0 could be from the return value of a previous function call
and its upper 32-bit value might contain some non-zero values.
The same applies to function arguments.

Second, the current code may permits removing SLL/SRA like below:
    %0:gpr32 = COPY $w0
    %1:gpr32 = COPY %0:gpr32
    ...
    %4:gpr = MOV_32_64 %1:gpr32
    %5:gpr = SLL_ri %4:gpr(tied-def 0), 32
    %6:gpr = SRA_ri %5:gpr(tied-def 0), 32
The reason is that it did not follow def-use chain to skip all
intermediate 32bit-to-32bit COPY instructions.

The current implementation is also very conservative for PHI
instructions. If any PHI insn component is another PHI or COPY insn,
it will just permit SLL/SRA.

This patch fixed the issue as follows:
 - During def/use chain traversal, if any physical register is read,
   SLL/SRA will be preserved as these physical registers are mostly
   from function return values or current function arguments.
 - Recursively visit all COPY and PHI instructions.
2019-11-20 15:19:59 -08:00
..
AsmParser [llvm] Migrate llvm::make_unique to std::make_unique 2019-08-15 15:54:37 +00:00
Disassembler Revert CMake: Make most target symbols hidden by default 2019-06-11 03:21:13 +00:00
MCTargetDesc [Mips] Use appropriate private label prefix based on Mips ABI 2019-10-23 12:24:35 +02:00
TargetInfo Revert CMake: Make most target symbols hidden by default 2019-06-11 03:21:13 +00:00
BPF.h bpf: fix wrong truncation elimination when there is back-edge/loop 2019-10-16 15:27:59 +00:00
BPF.td [BPF] add code-gen support for JMP32 instructions 2019-02-07 10:43:09 +00:00
BPFAbstractMemberAccess.cpp Fix uninitialized variable warning. NFCI. 2019-11-14 14:21:17 +00:00
BPFAsmPrinter.cpp Second attempt to add iterator_range::empty() 2019-10-07 18:14:24 +00:00
BPFCORE.h [BPF] Remove relocation for patchable externs 2019-10-10 15:33:09 +00:00
BPFCallingConv.td
BPFFrameLowering.cpp
BPFFrameLowering.h [Alignment][NFC] Use Align for TargetFrameLowering/Subtarget 2019-10-17 07:49:39 +00:00
BPFISelDAGToDAG.cpp bpf: fix wrong truncation elimination when there is back-edge/loop 2019-10-16 15:27:59 +00:00
BPFISelLowering.cpp [Alignment][NFC] Remove unneeded llvm:: scoping on Align types 2019-09-27 12:54:21 +00:00
BPFISelLowering.h [TargetLowering] Change getOptimalMemOpType to take a function attribute list 2019-04-30 08:38:12 +00:00
BPFInstrFormats.td [BPF] add code-gen support for JMP32 instructions 2019-02-07 10:43:09 +00:00
BPFInstrInfo.cpp Use MCRegister in copyPhysReg 2019-11-11 14:42:33 +05:30
BPFInstrInfo.h Use MCRegister in copyPhysReg 2019-11-11 14:42:33 +05:30
BPFInstrInfo.td [BPF] fix indirect call assembly code 2019-10-21 03:22:03 +00:00
BPFMCInstLower.cpp
BPFMCInstLower.h
BPFMIChecking.cpp Prune a LegacyDivergenceAnalysis and MachineLoopInfo include each 2019-10-19 01:31:09 +00:00
BPFMIPeephole.cpp [BPF] Fix a bug in peephole optimization 2019-11-20 15:19:59 -08:00
BPFMISimplifyPatchable.cpp [BPF] fix a CO-RE issue with -mattr=+alu32 2019-10-25 14:27:25 -07:00
BPFRegisterInfo.cpp Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM 2019-08-15 19:22:08 +00:00
BPFRegisterInfo.h CodeGen: Introduce a class for registers 2019-06-24 15:50:29 +00:00
BPFRegisterInfo.td
BPFSelectionDAGInfo.cpp
BPFSelectionDAGInfo.h
BPFSubtarget.cpp [BPF] turn on -mattr=+alu32 for cpu version v3 and later 2019-11-07 22:08:46 -08:00
BPFSubtarget.h [BPF] add code-gen support for JMP32 instructions 2019-02-07 10:43:09 +00:00
BPFTargetMachine.cpp bpf: fix wrong truncation elimination when there is back-edge/loop 2019-10-16 15:27:59 +00:00
BPFTargetMachine.h
BTF.def [BPF] Add BTF Var and DataSec Support 2019-03-16 15:36:31 +00:00
BTF.h [BPF] generate BTF_KIND_VARs for all non-static globals 2019-11-12 14:34:08 -08:00
BTFDebug.cpp [BPF] generate BTF_KIND_VARs for all non-static globals 2019-11-12 14:34:08 -08:00
BTFDebug.h [BPF] Remove relocation for patchable externs 2019-10-10 15:33:09 +00:00
CMakeLists.txt [BPF] Fix a typo in the file name 2019-07-09 18:35:46 +00:00
LLVMBuild.txt [BPF] Move InstPrinter files to MCTargetDesc. NFC 2019-05-11 01:13:21 +00:00