@@ -1392,34 +1392,33 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) {
1392
1392
1393
1393
// setcc's with boolean values can always be turned into bitwise operations
1394
1394
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)
1407
1398
Instruction *Xor = BinaryOperator::createXor (Op0, Op1, I.getName ()+" tmp" );
1408
1399
InsertNewInstBefore (Xor, I);
1409
1400
return BinaryOperator::createNot (Xor);
1410
1401
}
1402
+ case Instruction::SetNE:
1403
+ return BinaryOperator::createXor (Op0, Op1);
1411
1404
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:
1417
1414
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
+ }
1423
1422
}
1424
1423
1425
1424
// See if we are doing a comparison between a constant and an instruction that
0 commit comments