Skip to content

Commit ef09599

Browse files
author
John Criswell
committed
Merged in revision 1.239 from mainline.
llvm-svn: 15640
1 parent 841e694 commit ef09599

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,34 +1392,33 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) {
13921392

13931393
// setcc's with boolean values can always be turned into bitwise operations
13941394
if (Ty == Type::BoolTy) {
1395-
// If this is <, >, or !=, we can change this into a simple xor instruction
1396-
if (!isTrueWhenEqual(I))
1397-
return BinaryOperator::createXor(Op0, Op1);
1398-
1399-
// Otherwise we need to make a temporary intermediate instruction and insert
1400-
// it into the instruction stream. This is what we are after:
1401-
//
1402-
// seteq bool %A, %B -> ~(A^B)
1403-
// setle bool %A, %B -> ~A | B
1404-
// setge bool %A, %B -> A | ~B
1405-
//
1406-
if (I.getOpcode() == Instruction::SetEQ) { // seteq case
1395+
switch (I.getOpcode()) {
1396+
default: assert(0 && "Invalid setcc instruction!");
1397+
case Instruction::SetEQ: { // seteq bool %A, %B -> ~(A^B)
14071398
Instruction *Xor = BinaryOperator::createXor(Op0, Op1, I.getName()+"tmp");
14081399
InsertNewInstBefore(Xor, I);
14091400
return BinaryOperator::createNot(Xor);
14101401
}
1402+
case Instruction::SetNE:
1403+
return BinaryOperator::createXor(Op0, Op1);
14111404

1412-
// Handle the setXe cases...
1413-
assert(I.getOpcode() == Instruction::SetGE ||
1414-
I.getOpcode() == Instruction::SetLE);
1415-
1416-
if (I.getOpcode() == Instruction::SetGE)
1405+
case Instruction::SetGT:
1406+
std::swap(Op0, Op1); // Change setgt -> setlt
1407+
// FALL THROUGH
1408+
case Instruction::SetLT: { // setlt bool A, B -> ~X & Y
1409+
Instruction *Not = BinaryOperator::createNot(Op0, I.getName()+"tmp");
1410+
InsertNewInstBefore(Not, I);
1411+
return BinaryOperator::createAnd(Not, Op1);
1412+
}
1413+
case Instruction::SetGE:
14171414
std::swap(Op0, Op1); // Change setge -> setle
1418-
1419-
// Now we just have the SetLE case.
1420-
Instruction *Not = BinaryOperator::createNot(Op0, I.getName()+"tmp");
1421-
InsertNewInstBefore(Not, I);
1422-
return BinaryOperator::createOr(Not, Op1);
1415+
// FALL THROUGH
1416+
case Instruction::SetLE: { // setle bool %A, %B -> ~A | B
1417+
Instruction *Not = BinaryOperator::createNot(Op0, I.getName()+"tmp");
1418+
InsertNewInstBefore(Not, I);
1419+
return BinaryOperator::createOr(Not, Op1);
1420+
}
1421+
}
14231422
}
14241423

14251424
// See if we are doing a comparison between a constant and an instruction that

0 commit comments

Comments
 (0)