From c03a0cb01b7e40d74d3ed7a2c76d2ae4342c202a Mon Sep 17 00:00:00 2001 From: Brian Gaeke Date: Tue, 19 Nov 2002 09:08:47 +0000 Subject: 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 --- lib/Target/X86/X86ISelSimple.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'lib/Target/X86/X86ISelSimple.cpp') diff --git a/lib/Target/X86/X86ISelSimple.cpp b/lib/Target/X86/X86ISelSimple.cpp index d74bfd4..f0ffc67 100644 --- a/lib/Target/X86/X86ISelSimple.cpp +++ b/lib/Target/X86/X86ISelSimple.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)); + } } -- cgit v1.1