+ if (SI.getType() == Type::BoolTy)
+ if (ConstantBool *C = dyn_cast<ConstantBool>(TrueVal)) {
+ if (C == ConstantBool::True) {
+ // Change: A = select B, true, C --> A = or B, C
+ return BinaryOperator::create(Instruction::Or, CondVal, FalseVal);
+ } else {
+ // Change: A = select B, false, C --> A = and !B, C
+ Value *NotCond =
+ InsertNewInstBefore(BinaryOperator::createNot(CondVal,
+ "not."+CondVal->getName()), SI);
+ return BinaryOperator::create(Instruction::And, NotCond, FalseVal);
+ }
+ } else if (ConstantBool *C = dyn_cast<ConstantBool>(FalseVal)) {
+ if (C == ConstantBool::False) {
+ // Change: A = select B, C, false --> A = and B, C
+ return BinaryOperator::create(Instruction::And, CondVal, TrueVal);
+ } else {
+ // Change: A = select B, C, true --> A = or !B, C
+ Value *NotCond =
+ InsertNewInstBefore(BinaryOperator::createNot(CondVal,
+ "not."+CondVal->getName()), SI);
+ return BinaryOperator::create(Instruction::Or, NotCond, TrueVal);
+ }
+ }
+