|
25 | 25 | #include "llvm/CodeGen/MachineConstantPool.h" |
26 | 26 | #include "llvm/CodeGen/MachineDominators.h" |
27 | 27 | #include "llvm/CodeGen/MachineFrameInfo.h" |
28 | | -#include "llvm/CodeGen/MachineInstr.h" |
29 | 28 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
30 | 29 | #include "llvm/CodeGen/MachineModuleInfo.h" |
31 | | -#include "llvm/CodeGen/MachineOperand.h" |
32 | 30 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
33 | 31 | #include "llvm/CodeGen/StackMaps.h" |
34 | 32 | #include "llvm/IR/DebugInfoMetadata.h" |
35 | 33 | #include "llvm/IR/DerivedTypes.h" |
36 | 34 | #include "llvm/IR/Function.h" |
37 | | -#include "llvm/IR/InstrTypes.h" |
38 | 35 | #include "llvm/MC/MCAsmInfo.h" |
39 | 36 | #include "llvm/MC/MCExpr.h" |
40 | 37 | #include "llvm/MC/MCInst.h" |
@@ -967,101 +964,6 @@ inline static bool isTruncatedShiftCountForLEA(unsigned ShAmt) { |
967 | 964 | return ShAmt < 4 && ShAmt > 0; |
968 | 965 | } |
969 | 966 |
|
970 | | -static bool findRedundantFlagInstr(MachineInstr &CmpInstr, |
971 | | - MachineInstr &CmpValDefInstr, |
972 | | - const MachineRegisterInfo *MRI, |
973 | | - MachineInstr **AndInstr, |
974 | | - const TargetRegisterInfo *TRI, |
975 | | - bool &NoSignFlag, bool &ClearsOverflowFlag) { |
976 | | - if (CmpValDefInstr.getOpcode() != X86::SUBREG_TO_REG) |
977 | | - return false; |
978 | | - |
979 | | - if (CmpInstr.getOpcode() != X86::TEST64rr) |
980 | | - return false; |
981 | | - |
982 | | - // CmpInstr is a TEST64rr instruction, and `X86InstrInfo::analyzeCompare` |
983 | | - // guarantees that it's analyzable only if two registers are identical. |
984 | | - assert( |
985 | | - (CmpInstr.getOperand(0).getReg() == CmpInstr.getOperand(1).getReg()) && |
986 | | - "CmpInstr is an analyzable TEST64rr, and `X86InstrInfo::analyzeCompare` " |
987 | | - "requires two reg operands are the same."); |
988 | | - |
989 | | - // Caller (`X86InstrInfo::optimizeCompareInstr`) guarantees that |
990 | | - // `CmpValDefInstr` defines the value that's used by `CmpInstr`; in this case |
991 | | - // if `CmpValDefInstr` sets the EFLAGS, it is likely that `CmpInstr` is |
992 | | - // redundant. |
993 | | - assert( |
994 | | - (MRI->getVRegDef(CmpInstr.getOperand(0).getReg()) == &CmpValDefInstr) && |
995 | | - "Caller guarantees that TEST64rr is a user of SUBREG_TO_REG."); |
996 | | - |
997 | | - // As seen in X86 td files, CmpValDefInstr.getOperand(1).getImm() is typically |
998 | | - // 0. |
999 | | - if (CmpValDefInstr.getOperand(1).getImm() != 0) |
1000 | | - return false; |
1001 | | - |
1002 | | - // As seen in X86 td files, CmpValDefInstr.getOperand(3) is typically |
1003 | | - // sub_32bit or sub_xmm. |
1004 | | - if (CmpValDefInstr.getOperand(3).getImm() != X86::sub_32bit) |
1005 | | - return false; |
1006 | | - |
1007 | | - MachineInstr *VregDefInstr = |
1008 | | - MRI->getVRegDef(CmpValDefInstr.getOperand(2).getReg()); |
1009 | | - |
1010 | | - assert(VregDefInstr && "Must have a definition (SSA)"); |
1011 | | - |
1012 | | - // Requires `CmpValDefInstr` and `VregDefInstr` are from the same MBB |
1013 | | - // to simplify the subsequent analysis. |
1014 | | - // |
1015 | | - // FIXME: If `VregDefInstr->getParent()` is the only predecessor of |
1016 | | - // `CmpValDefInstr.getParent()`, this could be handled. |
1017 | | - if (VregDefInstr->getParent() != CmpValDefInstr.getParent()) |
1018 | | - return false; |
1019 | | - |
1020 | | - if (X86::isAND(VregDefInstr->getOpcode())) { |
1021 | | - // Get a sequence of instructions like |
1022 | | - // %reg = and* ... // Set EFLAGS |
1023 | | - // ... // EFLAGS not changed |
1024 | | - // %extended_reg = subreg_to_reg 0, %reg, %subreg.sub_32bit |
1025 | | - // test64rr %extended_reg, %extended_reg, implicit-def $eflags |
1026 | | - // |
1027 | | - // If subsequent readers use a subset of bits that don't change |
1028 | | - // after `and*` instructions, it's likely that the test64rr could |
1029 | | - // be optimized away. |
1030 | | - for (const MachineInstr &Instr : |
1031 | | - make_range(std::next(MachineBasicBlock::iterator(VregDefInstr)), |
1032 | | - MachineBasicBlock::iterator(CmpValDefInstr))) { |
1033 | | - // There are instructions between 'VregDefInstr' and |
1034 | | - // 'CmpValDefInstr' that modifies EFLAGS. |
1035 | | - if (Instr.modifiesRegister(X86::EFLAGS, TRI)) |
1036 | | - return false; |
1037 | | - } |
1038 | | - |
1039 | | - *AndInstr = VregDefInstr; |
1040 | | - |
1041 | | - // AND instruction will essentially update SF and clear OF, so |
1042 | | - // NoSignFlag should be false in the sense that SF is modified by `AND`. |
1043 | | - // |
1044 | | - // However, the implementation artifically sets `NoSignFlag` to true |
1045 | | - // to poison the SF bit; that is to say, if SF is looked at later, the |
1046 | | - // optimization (to erase TEST64rr) will be disabled. |
1047 | | - // |
1048 | | - // The reason to poison SF bit is that SF bit value could be different |
1049 | | - // in the `AND` and `TEST` operation; signed bit is not known for `AND`, |
1050 | | - // and is known to be 0 as a result of `TEST64rr`. |
1051 | | - // |
1052 | | - // FIXME: As opposed to poisoning the SF bit direclty, consider peeking into |
1053 | | - // the AND instruction and using the static information to guide peephole optimization if possible. |
1054 | | - // For example, it's possible to fold a conditional move into a copy |
1055 | | - // if the relevant EFLAG bits could be deduced from an immediate operand of and operation. |
1056 | | - // |
1057 | | - NoSignFlag = true; |
1058 | | - // ClearsOverflowFlag is true for AND operation (no surprise). |
1059 | | - ClearsOverflowFlag = true; |
1060 | | - return true; |
1061 | | - } |
1062 | | - return false; |
1063 | | -} |
1064 | | - |
1065 | 967 | bool X86InstrInfo::classifyLEAReg(MachineInstr &MI, const MachineOperand &Src, |
1066 | 968 | unsigned Opc, bool AllowSP, Register &NewSrc, |
1067 | 969 | bool &isKill, MachineOperand &ImplicitOp, |
@@ -4324,23 +4226,6 @@ bool X86InstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg, |
4324 | 4226 | MI = &Inst; |
4325 | 4227 | break; |
4326 | 4228 | } |
4327 | | - |
4328 | | - // Look back for the following pattern, in which case the test64rr |
4329 | | - // instruction could be erased. |
4330 | | - // |
4331 | | - // Example: |
4332 | | - // %reg = and32ri %in_reg, 5 |
4333 | | - // ... // EFLAGS not changed. |
4334 | | - // %src_reg = subreg_to_reg 0, %reg, %subreg.sub_index |
4335 | | - // test64rr %src_reg, %src_reg, implicit-def $eflags |
4336 | | - MachineInstr *AndInstr = nullptr; |
4337 | | - if (IsCmpZero && |
4338 | | - findRedundantFlagInstr(CmpInstr, Inst, MRI, &AndInstr, TRI, |
4339 | | - NoSignFlag, ClearsOverflowFlag)) { |
4340 | | - assert(AndInstr != nullptr && X86::isAND(AndInstr->getOpcode())); |
4341 | | - MI = AndInstr; |
4342 | | - break; |
4343 | | - } |
4344 | 4229 | // Cannot find other candidates before definition of SrcReg. |
4345 | 4230 | return false; |
4346 | 4231 | } |
|
0 commit comments