diff options
author | Brian Gaeke <gaeke@uiuc.edu> | 2002-11-19 09:08:47 +0000 |
---|---|---|
committer | Brian Gaeke <gaeke@uiuc.edu> | 2002-11-19 09:08:47 +0000 |
commit | c03a0cb01b7e40d74d3ed7a2c76d2ae4342c202a (patch) | |
tree | b05d6efd8a04e43750e866eafd3a9205afb45960 /lib/Target/X86/InstSelectSimple.cpp | |
parent | a1a64f8f275efe17725119d59441df10bc30c711 (diff) |
Brian Gaeke says:
lib/Target/X86/InstSelectSimple.cpp: Add a little something to
visitBranchInst which supports conditional branches.
lib/Target/X86/X86InstrInfo.def: Add defs of JNE, JE, CMPri8
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4755 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/X86/InstSelectSimple.cpp')
-rw-r--r-- | lib/Target/X86/InstSelectSimple.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/lib/Target/X86/InstSelectSimple.cpp b/lib/Target/X86/InstSelectSimple.cpp index d74bfd4912..f0ffc679ed 100644 --- a/lib/Target/X86/InstSelectSimple.cpp +++ b/lib/Target/X86/InstSelectSimple.cpp @@ -386,17 +386,31 @@ void ISel::visitReturnInst (ReturnInst &I) { BuildMI(BB, X86::RET, 0); } - /// visitBranchInst - Handle conditional and unconditional branches here. Note /// that since code layout is frozen at this point, that if we are trying to /// jump to a block that is the immediate successor of the current block, we can /// just make a fall-through. (but we don't currently). /// -void ISel::visitBranchInst(BranchInst &BI) { - if (BI.isConditional()) // Only handles unconditional branches so far... - visitInstruction(BI); - - BuildMI(BB, X86::JMP, 1).addPCDisp(BI.getSuccessor(0)); +void +ISel::visitBranchInst (BranchInst & BI) +{ + if (BI.isConditional ()) + { + BasicBlock *ifTrue = BI.getSuccessor (0); + BasicBlock *ifFalse = BI.getSuccessor (1); // this is really unobvious + + // simplest thing I can think of: compare condition with zero, + // followed by jump-if-equal to ifFalse, and jump-if-nonequal to + // ifTrue + unsigned int condReg = getReg (BI.getCondition ()); + BuildMI (BB, X86::CMPri8, 2, X86::EFLAGS).addReg (condReg).addZImm (0); + BuildMI (BB, X86::JNE, 1).addPCDisp (BI.getSuccessor (0)); + BuildMI (BB, X86::JE, 1).addPCDisp (BI.getSuccessor (1)); + } + else // unconditional branch + { + BuildMI (BB, X86::JMP, 1).addPCDisp (BI.getSuccessor (0)); + } } |