Skip to content

Commit fdf24cc

Browse files
committed
[InstSimplify] Move Select with bittest folds.
Preparation to handle trunc to i1 in this fold.
1 parent 19032bf commit fdf24cc

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4612,14 +4612,16 @@ static Value *simplifyCmpSelOfMaxMin(Value *CmpLHS, Value *CmpRHS,
46124612
return nullptr;
46134613
}
46144614

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);
46234625

46244626
return nullptr;
46254627
}
@@ -4728,11 +4730,6 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal,
47284730
return FalseVal;
47294731
}
47304732

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-
47364733
// If we have a scalar equality comparison, then we know the value in one of
47374734
// the arms of the select. See if substituting this value into the arm and
47384735
// simplifying the result yields the same value as the other arm.
@@ -4984,6 +4981,9 @@ static Value *simplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal,
49844981
simplifySelectWithICmpCond(Cond, TrueVal, FalseVal, Q, MaxRecurse))
49854982
return V;
49864983

4984+
if (Value *V = simplifySelectWithBitTest(Cond, TrueVal, FalseVal))
4985+
return V;
4986+
49874987
if (Value *V = simplifySelectWithFCmp(Cond, TrueVal, FalseVal, Q, MaxRecurse))
49884988
return V;
49894989

0 commit comments

Comments
 (0)