@@ -4397,7 +4397,7 @@ static Value *simplifyWithOpsReplaced(Value *V,
4397
4397
// (Op == -1) ? -1 : (Op | (binop C, Op) --> Op | (binop C, Op)
4398
4398
Constant *Absorber = ConstantExpr::getBinOpAbsorber (Opcode, I->getType ());
4399
4399
if ((NewOps[0 ] == Absorber || NewOps[1 ] == Absorber) &&
4400
- all_of (ValidReplacements,
4400
+ any_of (ValidReplacements,
4401
4401
[=](const auto &Rep) { return impliesPoison (BO, Rep.first ); }))
4402
4402
return Absorber;
4403
4403
}
@@ -4617,17 +4617,16 @@ static Value *simplifySelectWithFakeICmpEq(Value *CmpLHS, Value *CmpRHS,
4617
4617
4618
4618
// / Try to simplify a select instruction when its condition operand is an
4619
4619
// / integer equality or floating-point equivalence comparison.
4620
- static Value *simplifySelectWithEquivalence (Value *CmpLHS, Value *CmpRHS,
4621
- Value *TrueVal, Value *FalseVal,
4622
- const SimplifyQuery &Q,
4623
- unsigned MaxRecurse) {
4624
- if (simplifyWithOpReplaced (FalseVal, CmpLHS, CmpRHS, Q.getWithoutUndef (),
4625
- /* AllowRefinement */ false ,
4626
- /* DropFlags */ nullptr , MaxRecurse) == TrueVal)
4620
+ static Value *simplifySelectWithEquivalence (
4621
+ ArrayRef<std::pair<Value *, Value *>> Replacements, Value *TrueVal,
4622
+ Value *FalseVal, const SimplifyQuery &Q, unsigned MaxRecurse) {
4623
+ if (simplifyWithOpsReplaced (FalseVal, Replacements, Q.getWithoutUndef (),
4624
+ /* AllowRefinement */ false ,
4625
+ /* DropFlags */ nullptr , MaxRecurse) == TrueVal)
4627
4626
return FalseVal;
4628
- if (simplifyWithOpReplaced (TrueVal, CmpLHS, CmpRHS , Q,
4629
- /* AllowRefinement */ true ,
4630
- /* DropFlags */ nullptr , MaxRecurse) == FalseVal)
4627
+ if (simplifyWithOpsReplaced (TrueVal, Replacements , Q,
4628
+ /* AllowRefinement */ true ,
4629
+ /* DropFlags */ nullptr , MaxRecurse) == FalseVal)
4631
4630
return FalseVal;
4632
4631
4633
4632
return nullptr ;
@@ -4721,10 +4720,10 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal,
4721
4720
// the arms of the select. See if substituting this value into the arm and
4722
4721
// simplifying the result yields the same value as the other arm.
4723
4722
if (Pred == ICmpInst::ICMP_EQ) {
4724
- if (Value *V = simplifySelectWithEquivalence (CmpLHS, CmpRHS, TrueVal,
4723
+ if (Value *V = simplifySelectWithEquivalence ({{ CmpLHS, CmpRHS}} , TrueVal,
4725
4724
FalseVal, Q, MaxRecurse))
4726
4725
return V;
4727
- if (Value *V = simplifySelectWithEquivalence (CmpRHS, CmpLHS, TrueVal,
4726
+ if (Value *V = simplifySelectWithEquivalence ({{ CmpRHS, CmpLHS}} , TrueVal,
4728
4727
FalseVal, Q, MaxRecurse))
4729
4728
return V;
4730
4729
@@ -4734,23 +4733,29 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal,
4734
4733
if (match (CmpLHS, m_Or (m_Value (X), m_Value (Y))) &&
4735
4734
match (CmpRHS, m_Zero ())) {
4736
4735
// (X | Y) == 0 implies X == 0 and Y == 0.
4737
- if (Value *V = simplifySelectWithEquivalence (X, CmpRHS, TrueVal, FalseVal,
4738
- Q, MaxRecurse))
4736
+ if (Value *V = simplifySelectWithEquivalence (
4737
+ {{X, CmpRHS}, {Y, CmpRHS}}, TrueVal, FalseVal, Q, MaxRecurse))
4739
4738
return V;
4740
- if (Value *V = simplifySelectWithEquivalence (Y, CmpRHS, TrueVal, FalseVal,
4741
- Q, MaxRecurse))
4739
+ if (Value *V = simplifySelectWithEquivalence ({{X, CmpRHS}}, TrueVal,
4740
+ FalseVal, Q, MaxRecurse))
4741
+ return V;
4742
+ if (Value *V = simplifySelectWithEquivalence ({{Y, CmpRHS}}, TrueVal,
4743
+ FalseVal, Q, MaxRecurse))
4742
4744
return V;
4743
4745
}
4744
4746
4745
4747
// select((X & Y) == -1 ? X : -1) --> -1 (commuted 2 ways)
4746
4748
if (match (CmpLHS, m_And (m_Value (X), m_Value (Y))) &&
4747
4749
match (CmpRHS, m_AllOnes ())) {
4748
4750
// (X & Y) == -1 implies X == -1 and Y == -1.
4749
- if (Value *V = simplifySelectWithEquivalence (X, CmpRHS, TrueVal, FalseVal,
4750
- Q, MaxRecurse))
4751
+ if (Value *V = simplifySelectWithEquivalence (
4752
+ {{X, CmpRHS}, {Y, CmpRHS}}, TrueVal, FalseVal, Q, MaxRecurse))
4753
+ return V;
4754
+ if (Value *V = simplifySelectWithEquivalence ({{X, CmpRHS}}, TrueVal,
4755
+ FalseVal, Q, MaxRecurse))
4751
4756
return V;
4752
- if (Value *V = simplifySelectWithEquivalence (Y, CmpRHS, TrueVal, FalseVal ,
4753
- Q, MaxRecurse))
4757
+ if (Value *V = simplifySelectWithEquivalence ({{ Y, CmpRHS}} , TrueVal,
4758
+ FalseVal, Q, MaxRecurse))
4754
4759
return V;
4755
4760
}
4756
4761
}
@@ -4779,11 +4784,11 @@ static Value *simplifySelectWithFCmp(Value *Cond, Value *T, Value *F,
4779
4784
// This transforms is safe if at least one operand is known to not be zero.
4780
4785
// Otherwise, the select can change the sign of a zero operand.
4781
4786
if (IsEquiv) {
4782
- if (Value *V =
4783
- simplifySelectWithEquivalence (CmpLHS, CmpRHS, T, F, Q, MaxRecurse))
4787
+ if (Value *V = simplifySelectWithEquivalence ({{CmpLHS, CmpRHS}}, T, F, Q,
4788
+ MaxRecurse))
4784
4789
return V;
4785
- if (Value *V =
4786
- simplifySelectWithEquivalence (CmpRHS, CmpLHS, T, F, Q, MaxRecurse))
4790
+ if (Value *V = simplifySelectWithEquivalence ({{CmpRHS, CmpLHS}}, T, F, Q,
4791
+ MaxRecurse))
4787
4792
return V;
4788
4793
}
4789
4794
0 commit comments