@@ -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,19 +4617,18 @@ 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) {
4620
+ static Value *simplifySelectWithEquivalence (
4621
+ ArrayRef<std::pair<Value *, Value *>> Replacements, Value *TrueVal,
4622
+ Value *FalseVal, const SimplifyQuery &Q, unsigned MaxRecurse) {
4624
4623
Value *SimplifiedFalseVal =
4625
- simplifyWithOpReplaced (FalseVal, CmpLHS, CmpRHS , Q.getWithoutUndef (),
4624
+ simplifyWithOpReplaced (FalseVal, Replacements , Q.getWithoutUndef (),
4626
4625
/* AllowRefinement */ false ,
4627
4626
/* DropFlags */ nullptr , MaxRecurse);
4628
4627
if (!SimplifiedFalseVal)
4629
4628
SimplifiedFalseVal = FalseVal;
4630
4629
4631
4630
Value *SimplifiedTrueVal =
4632
- simplifyWithOpReplaced (TrueVal, CmpLHS, CmpRHS , Q,
4631
+ simplifyWithOpReplaced (TrueVal, Replacements , Q,
4633
4632
/* AllowRefinement */ true ,
4634
4633
/* DropFlags */ nullptr , MaxRecurse);
4635
4634
if (!SimplifiedTrueVal)
@@ -4729,10 +4728,10 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal,
4729
4728
// the arms of the select. See if substituting this value into the arm and
4730
4729
// simplifying the result yields the same value as the other arm.
4731
4730
if (Pred == ICmpInst::ICMP_EQ) {
4732
- if (Value *V = simplifySelectWithEquivalence (CmpLHS, CmpRHS, TrueVal,
4731
+ if (Value *V = simplifySelectWithEquivalence ({{ CmpLHS, CmpRHS}} , TrueVal,
4733
4732
FalseVal, Q, MaxRecurse))
4734
4733
return V;
4735
- if (Value *V = simplifySelectWithEquivalence (CmpRHS, CmpLHS, TrueVal,
4734
+ if (Value *V = simplifySelectWithEquivalence ({{ CmpRHS, CmpLHS}} , TrueVal,
4736
4735
FalseVal, Q, MaxRecurse))
4737
4736
return V;
4738
4737
@@ -4742,23 +4741,29 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal,
4742
4741
if (match (CmpLHS, m_Or (m_Value (X), m_Value (Y))) &&
4743
4742
match (CmpRHS, m_Zero ())) {
4744
4743
// (X | Y) == 0 implies X == 0 and Y == 0.
4745
- if (Value *V = simplifySelectWithEquivalence (X, CmpRHS, TrueVal, FalseVal,
4746
- Q, MaxRecurse))
4744
+ if (Value *V = simplifySelectWithEquivalence (
4745
+ {{X, CmpRHS}, {Y, CmpRHS}}, TrueVal, FalseVal, Q, MaxRecurse))
4747
4746
return V;
4748
- if (Value *V = simplifySelectWithEquivalence (Y, CmpRHS, TrueVal, FalseVal,
4749
- Q, MaxRecurse))
4747
+ if (Value *V = simplifySelectWithEquivalence ({{X, CmpRHS}}, TrueVal,
4748
+ FalseVal, Q, MaxRecurse))
4749
+ return V;
4750
+ if (Value *V = simplifySelectWithEquivalence ({{Y, CmpRHS}}, TrueVal,
4751
+ FalseVal, Q, MaxRecurse))
4750
4752
return V;
4751
4753
}
4752
4754
4753
4755
// select((X & Y) == -1 ? X : -1) --> -1 (commuted 2 ways)
4754
4756
if (match (CmpLHS, m_And (m_Value (X), m_Value (Y))) &&
4755
4757
match (CmpRHS, m_AllOnes ())) {
4756
4758
// (X & Y) == -1 implies X == -1 and Y == -1.
4757
- if (Value *V = simplifySelectWithEquivalence (X, CmpRHS, TrueVal, FalseVal,
4758
- Q, MaxRecurse))
4759
+ if (Value *V = simplifySelectWithEquivalence (
4760
+ {{X, CmpRHS}, {Y, CmpRHS}}, TrueVal, FalseVal, Q, MaxRecurse))
4761
+ return V;
4762
+ if (Value *V = simplifySelectWithEquivalence ({{X, CmpRHS}}, TrueVal,
4763
+ FalseVal, Q, MaxRecurse))
4759
4764
return V;
4760
- if (Value *V = simplifySelectWithEquivalence (Y, CmpRHS, TrueVal, FalseVal ,
4761
- Q, MaxRecurse))
4765
+ if (Value *V = simplifySelectWithEquivalence ({{ Y, CmpRHS}} , TrueVal,
4766
+ FalseVal, Q, MaxRecurse))
4762
4767
return V;
4763
4768
}
4764
4769
}
@@ -4787,11 +4792,11 @@ static Value *simplifySelectWithFCmp(Value *Cond, Value *T, Value *F,
4787
4792
// This transforms is safe if at least one operand is known to not be zero.
4788
4793
// Otherwise, the select can change the sign of a zero operand.
4789
4794
if (IsEquiv) {
4790
- if (Value *V =
4791
- simplifySelectWithEquivalence (CmpLHS, CmpRHS, T, F, Q, MaxRecurse))
4795
+ if (Value *V = simplifySelectWithEquivalence ({{CmpLHS, CmpRHS}}, T, F, Q,
4796
+ MaxRecurse))
4792
4797
return V;
4793
- if (Value *V =
4794
- simplifySelectWithEquivalence (CmpRHS, CmpLHS, T, F, Q, MaxRecurse))
4798
+ if (Value *V = simplifySelectWithEquivalence ({{CmpRHS, CmpLHS}}, T, F, Q,
4799
+ MaxRecurse))
4795
4800
return V;
4796
4801
}
4797
4802
0 commit comments