@@ -3965,12 +3965,18 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal,
3965
3965
if (!match (CondVal, m_ICmp (Pred, m_Value (CmpLHS), m_Value (CmpRHS))))
3966
3966
return nullptr ;
3967
3967
3968
- if (ICmpInst::isEquality (Pred) && match (CmpRHS, m_Zero ())) {
3968
+ // Canonicalize ne to eq predicate.
3969
+ if (Pred == ICmpInst::ICMP_NE) {
3970
+ Pred = ICmpInst::ICMP_EQ;
3971
+ std::swap (TrueVal, FalseVal);
3972
+ }
3973
+
3974
+ if (Pred == ICmpInst::ICMP_EQ && match (CmpRHS, m_Zero ())) {
3969
3975
Value *X;
3970
3976
const APInt *Y;
3971
3977
if (match (CmpLHS, m_And (m_Value (X), m_APInt (Y))))
3972
3978
if (Value *V = simplifySelectBitTest (TrueVal, FalseVal, X, Y,
3973
- Pred == ICmpInst::ICMP_EQ ))
3979
+ /* TrueWhenUnset= */ true ))
3974
3980
return V;
3975
3981
3976
3982
// Test for a bogus zero-shift-guard-op around funnel-shift or rotate.
@@ -3981,13 +3987,7 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal,
3981
3987
m_Value (ShAmt)));
3982
3988
// (ShAmt == 0) ? fshl(X, *, ShAmt) : X --> X
3983
3989
// (ShAmt == 0) ? fshr(*, X, ShAmt) : X --> X
3984
- if (match (TrueVal, isFsh) && FalseVal == X && CmpLHS == ShAmt &&
3985
- Pred == ICmpInst::ICMP_EQ)
3986
- return X;
3987
- // (ShAmt != 0) ? X : fshl(X, *, ShAmt) --> X
3988
- // (ShAmt != 0) ? X : fshr(*, X, ShAmt) --> X
3989
- if (match (FalseVal, isFsh) && TrueVal == X && CmpLHS == ShAmt &&
3990
- Pred == ICmpInst::ICMP_NE)
3990
+ if (match (TrueVal, isFsh) && FalseVal == X && CmpLHS == ShAmt)
3991
3991
return X;
3992
3992
3993
3993
// Test for a zero-shift-guard-op around rotates. These are used to
@@ -4001,11 +4001,6 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal,
4001
4001
m_Intrinsic<Intrinsic::fshr>(m_Value (X),
4002
4002
m_Deferred (X),
4003
4003
m_Value (ShAmt)));
4004
- // (ShAmt != 0) ? fshl(X, X, ShAmt) : X --> fshl(X, X, ShAmt)
4005
- // (ShAmt != 0) ? fshr(X, X, ShAmt) : X --> fshr(X, X, ShAmt)
4006
- if (match (TrueVal, isRotate) && FalseVal == X && CmpLHS == ShAmt &&
4007
- Pred == ICmpInst::ICMP_NE)
4008
- return TrueVal;
4009
4004
// (ShAmt == 0) ? X : fshl(X, X, ShAmt) --> fshl(X, X, ShAmt)
4010
4005
// (ShAmt == 0) ? X : fshr(X, X, ShAmt) --> fshr(X, X, ShAmt)
4011
4006
if (match (FalseVal, isRotate) && TrueVal == X && CmpLHS == ShAmt &&
@@ -4032,17 +4027,6 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal,
4032
4027
SimplifyWithOpReplaced (TrueVal, CmpRHS, CmpLHS, Q, MaxRecurse) ==
4033
4028
FalseVal)
4034
4029
return FalseVal;
4035
- } else if (Pred == ICmpInst::ICMP_NE) {
4036
- if (SimplifyWithOpReplaced (TrueVal, CmpLHS, CmpRHS, Q, MaxRecurse) ==
4037
- FalseVal ||
4038
- SimplifyWithOpReplaced (TrueVal, CmpRHS, CmpLHS, Q, MaxRecurse) ==
4039
- FalseVal)
4040
- return TrueVal;
4041
- if (SimplifyWithOpReplaced (FalseVal, CmpLHS, CmpRHS, Q, MaxRecurse) ==
4042
- TrueVal ||
4043
- SimplifyWithOpReplaced (FalseVal, CmpRHS, CmpLHS, Q, MaxRecurse) ==
4044
- TrueVal)
4045
- return TrueVal;
4046
4030
}
4047
4031
4048
4032
return nullptr ;
0 commit comments