summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManman Ren <mren@apple.com>2012-06-06 23:53:03 +0000
committerManman Ren <mren@apple.com>2012-06-06 23:53:03 +0000
commit2afde7782dfa56b2e46f79598bdb5f1e09471941 (patch)
treec3a07b4c2b416d79bd3e0dc7462b07f5e45a1547
parentaed04d12f8e336d4960b49ad8d09ac2eb5785f1f (diff)
downloadllvm-2afde7782dfa56b2e46f79598bdb5f1e09471941.tar.gz
llvm-2afde7782dfa56b2e46f79598bdb5f1e09471941.tar.bz2
llvm-2afde7782dfa56b2e46f79598bdb5f1e09471941.tar.xz
Revert r157755.
The commit is intended to fix rdar://11540023. It is implemented as part of peephole optimization. We can actually implement this in the SelectionDAG lowering phase. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158122 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Target/TargetInstrInfo.h8
-rw-r--r--lib/CodeGen/PeepholeOptimizer.cpp1
-rw-r--r--lib/Target/X86/X86InstrInfo.cpp38
-rw-r--r--lib/Target/X86/X86InstrInfo.h3
-rw-r--r--test/CodeGen/X86/jump_sign.ll11
5 files changed, 0 insertions, 61 deletions
diff --git a/include/llvm/Target/TargetInstrInfo.h b/include/llvm/Target/TargetInstrInfo.h
index 693166f552..67b61ec77e 100644
--- a/include/llvm/Target/TargetInstrInfo.h
+++ b/include/llvm/Target/TargetInstrInfo.h
@@ -640,14 +640,6 @@ public:
return false;
}
- /// OptimizeSubInstr - See if the SUB instruction can be converted into
- /// something more efficient E.g., on X86, we can replace SUB with CMP
- /// if the actual result of SUB is not used.
- virtual bool OptimizeSubInstr(MachineInstr *SubInstr,
- const MachineRegisterInfo *MRI) const {
- return false;
- }
-
/// FoldImmediate - 'Reg' is known to be defined by a move immediate
/// instruction, try to fold the immediate into the use instruction.
virtual bool FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI,
diff --git a/lib/CodeGen/PeepholeOptimizer.cpp b/lib/CodeGen/PeepholeOptimizer.cpp
index d7d112f1d9..81cf9011d1 100644
--- a/lib/CodeGen/PeepholeOptimizer.cpp
+++ b/lib/CodeGen/PeepholeOptimizer.cpp
@@ -472,7 +472,6 @@ bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
if (SeenMoveImm)
Changed |= foldImmediate(MI, MBB, ImmDefRegs, ImmDefMIs);
}
- Changed |= TII->OptimizeSubInstr(MI, MRI);
First = false;
PMII = MII;
diff --git a/lib/Target/X86/X86InstrInfo.cpp b/lib/Target/X86/X86InstrInfo.cpp
index 197b9c683d..7d5b25084e 100644
--- a/lib/Target/X86/X86InstrInfo.cpp
+++ b/lib/Target/X86/X86InstrInfo.cpp
@@ -2793,44 +2793,6 @@ void X86InstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
NewMIs.push_back(MIB);
}
-bool X86InstrInfo::
-OptimizeSubInstr(MachineInstr *SubInstr, const MachineRegisterInfo *MRI) const {
- // If destination is a memory operand, do not perform this optimization.
- if ((SubInstr->getOpcode() != X86::SUB64rr) &&
- (SubInstr->getOpcode() != X86::SUB32rr) &&
- (SubInstr->getOpcode() != X86::SUB16rr) &&
- (SubInstr->getOpcode() != X86::SUB8rr) &&
- (SubInstr->getOpcode() != X86::SUB64ri32) &&
- (SubInstr->getOpcode() != X86::SUB64ri8) &&
- (SubInstr->getOpcode() != X86::SUB32ri) &&
- (SubInstr->getOpcode() != X86::SUB32ri8) &&
- (SubInstr->getOpcode() != X86::SUB16ri) &&
- (SubInstr->getOpcode() != X86::SUB16ri8) &&
- (SubInstr->getOpcode() != X86::SUB8ri))
- return false;
- unsigned DestReg = SubInstr->getOperand(0).getReg();
- if (MRI->use_begin(DestReg) != MRI->use_end())
- return false;
-
- // There is no use of the destination register, we can replace SUB with CMP.
- switch (SubInstr->getOpcode()) {
- default: break;
- case X86::SUB64rr: SubInstr->setDesc(get(X86::CMP64rr)); break;
- case X86::SUB32rr: SubInstr->setDesc(get(X86::CMP32rr)); break;
- case X86::SUB16rr: SubInstr->setDesc(get(X86::CMP16rr)); break;
- case X86::SUB8rr: SubInstr->setDesc(get(X86::CMP8rr)); break;
- case X86::SUB64ri32: SubInstr->setDesc(get(X86::CMP64ri32)); break;
- case X86::SUB64ri8: SubInstr->setDesc(get(X86::CMP64ri8)); break;
- case X86::SUB32ri: SubInstr->setDesc(get(X86::CMP32ri)); break;
- case X86::SUB32ri8: SubInstr->setDesc(get(X86::CMP32ri8)); break;
- case X86::SUB16ri: SubInstr->setDesc(get(X86::CMP16ri)); break;
- case X86::SUB16ri8: SubInstr->setDesc(get(X86::CMP16ri8)); break;
- case X86::SUB8ri: SubInstr->setDesc(get(X86::CMP8ri)); break;
- }
- SubInstr->RemoveOperand(0);
- return true;
-}
-
/// Expand2AddrUndef - Expand a single-def pseudo instruction to a two-addr
/// instruction with two undef reads of the register being defined. This is
/// used for mapping:
diff --git a/lib/Target/X86/X86InstrInfo.h b/lib/Target/X86/X86InstrInfo.h
index 088c49f629..5ae6b99e5a 100644
--- a/lib/Target/X86/X86InstrInfo.h
+++ b/lib/Target/X86/X86InstrInfo.h
@@ -364,9 +364,6 @@ public:
const MachineInstr *DefMI, unsigned DefIdx,
const MachineInstr *UseMI, unsigned UseIdx) const;
- virtual bool OptimizeSubInstr(MachineInstr *SubInstr,
- const MachineRegisterInfo *MRI) const;
-
private:
MachineInstr * convertToThreeAddressWithLEA(unsigned MIOpc,
MachineFunction::iterator &MFI,
diff --git a/test/CodeGen/X86/jump_sign.ll b/test/CodeGen/X86/jump_sign.ll
index cf5408e071..94cbe5d193 100644
--- a/test/CodeGen/X86/jump_sign.ll
+++ b/test/CodeGen/X86/jump_sign.ll
@@ -83,14 +83,3 @@ entry:
%cond = select i1 %cmp, i32 %sub, i32 0
ret i32 %cond
}
-; rdar://11540023
-define i64 @n(i64 %x, i64 %y) nounwind {
-entry:
-; CHECK: n:
-; CHECK-NOT: sub
-; CHECK: cmp
- %sub = sub nsw i64 %x, %y
- %cmp = icmp slt i64 %sub, 0
- %y.x = select i1 %cmp, i64 %y, i64 %x
- ret i64 %y.x
-}