@@ -4612,14 +4612,16 @@ static Value *simplifyCmpSelOfMaxMin(Value *CmpLHS, Value *CmpRHS,
4612
4612
return nullptr ;
4613
4613
}
4614
4614
4615
- // / An alternative way to test if a bit is set or not uses sgt/slt instead of
4616
- // / eq/ne.
4617
- static Value *simplifySelectWithFakeICmpEq (Value *CmpLHS, Value *CmpRHS,
4618
- CmpPredicate Pred, Value *TrueVal,
4619
- Value *FalseVal) {
4620
- if (auto Res = decomposeBitTestICmp (CmpLHS, CmpRHS, Pred))
4621
- return simplifySelectBitTest (TrueVal, FalseVal, Res->X , &Res->Mask ,
4622
- Res->Pred == ICmpInst::ICMP_EQ);
4615
+ // / An alternative way to test if a bit is set or not uses e.g. sgt/slt instead
4616
+ // / of eq/ne.
4617
+ static Value *simplifySelectWithBitTest (Value *CondVal, Value *TrueVal,
4618
+ Value *FalseVal) {
4619
+
4620
+ if (auto *ICmp = dyn_cast<ICmpInst>(CondVal))
4621
+ if (auto Res = decomposeBitTestICmp (
4622
+ ICmp->getOperand (0 ), ICmp->getOperand (1 ), ICmp->getPredicate ()))
4623
+ return simplifySelectBitTest (TrueVal, FalseVal, Res->X , &Res->Mask ,
4624
+ Res->Pred == ICmpInst::ICMP_EQ);
4623
4625
4624
4626
return nullptr ;
4625
4627
}
@@ -4728,11 +4730,6 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal,
4728
4730
return FalseVal;
4729
4731
}
4730
4732
4731
- // Check for other compares that behave like bit test.
4732
- if (Value *V =
4733
- simplifySelectWithFakeICmpEq (CmpLHS, CmpRHS, Pred, TrueVal, FalseVal))
4734
- return V;
4735
-
4736
4733
// If we have a scalar equality comparison, then we know the value in one of
4737
4734
// the arms of the select. See if substituting this value into the arm and
4738
4735
// simplifying the result yields the same value as the other arm.
@@ -4984,6 +4981,9 @@ static Value *simplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal,
4984
4981
simplifySelectWithICmpCond (Cond, TrueVal, FalseVal, Q, MaxRecurse))
4985
4982
return V;
4986
4983
4984
+ if (Value *V = simplifySelectWithBitTest (Cond, TrueVal, FalseVal))
4985
+ return V;
4986
+
4987
4987
if (Value *V = simplifySelectWithFCmp (Cond, TrueVal, FalseVal, Q, MaxRecurse))
4988
4988
return V;
4989
4989
0 commit comments