[llvm-bugs] [Bug 25745] New: Problem in InstCombineSelect.cpp handling SPF_ABS/SPF_NABS
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Dec 4 12:17:16 PST 2015
https://llvm.org/bugs/show_bug.cgi?id=25745
Bug ID: 25745
Summary: Problem in InstCombineSelect.cpp handling
SPF_ABS/SPF_NABS
Product: new-bugs
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: cvick at codeaurora.org
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
In InstCombineSelect.cpp, visitSelectInst calls matchSelectPattern. If you
have a signed integer compare to a constant 0 or 1, matchSelectPattern returns
the flavor of SPF_ABS or SPF_NABS. Then in the subsequent call to
getCmpPredicateForMinMax, those values are not handled, and you hit an
unreachable.
InstCombineSelect 1288,1297 (in visitSelectInst)
Value *LHS, *RHS, *LHS2, *RHS2;
Instruction::CastOps CastOp;
SelectPatternResult SPR = matchSelectPattern(&SI, LHS, RHS, &CastOp);
auto SPF = SPR.Flavor;
if (SPF) {
// Canonicalize so that type casts are outside select patterns.
if (LHS->getType()->getPrimitiveSizeInBits() !=
SI.getType()->getPrimitiveSizeInBits()) {
CmpInst::Predicate Pred = getCmpPredicateForMinMax(SPF, SPR.Ordered);
InstCombineSelect 49,68
static CmpInst::Predicate getCmpPredicateForMinMax(SelectPatternFlavor SPF,
bool Ordered=false) {
switch (SPF) {
default:
llvm_unreachable("unhandled!");
case SPF_SMIN:
return ICmpInst::ICMP_SLT;
case SPF_UMIN:
return ICmpInst::ICMP_ULT;
case SPF_SMAX:
return ICmpInst::ICMP_SGT;
case SPF_UMAX:
return ICmpInst::ICMP_UGT;
case SPF_FMINNUM:
return Ordered ? FCmpInst::FCMP_OLT : FCmpInst::FCMP_ULT;
case SPF_FMAXNUM:
return Ordered ? FCmpInst::FCMP_OGT : FCmpInst::FCMP_UGT;
}
}
ValueTracking.cpp 3960,3987 (in MatchSelectPattern)
if (ConstantInt *C1 = dyn_cast<ConstantInt>(CmpRHS)) {
if ((CmpLHS == TrueVal && match(FalseVal, m_Neg(m_Specific(CmpLHS)))) ||
(CmpLHS == FalseVal && match(TrueVal, m_Neg(m_Specific(CmpLHS))))) {
// ABS(X) ==> (X >s 0) ? X : -X and (X >s -1) ? X : -X
// NABS(X) ==> (X >s 0) ? -X : X and (X >s -1) ? -X : X
if (Pred == ICmpInst::ICMP_SGT && (C1->isZero() || C1->isMinusOne())) {
return {(CmpLHS == TrueVal) ? SPF_ABS : SPF_NABS, SPNB_NA, false};
}
// ABS(X) ==> (X <s 0) ? -X : X and (X <s 1) ? -X : X
// NABS(X) ==> (X <s 0) ? X : -X and (X <s 1) ? X : -X
if (Pred == ICmpInst::ICMP_SLT && (C1->isZero() || C1->isOne())) {
return {(CmpLHS == FalseVal) ? SPF_ABS : SPF_NABS, SPNB_NA, false};
}
}
// Y >s C ? ~Y : ~C == ~Y <s ~C ? ~Y : ~C = SMIN(~Y, ~C)
if (const auto *C2 = dyn_cast<ConstantInt>(FalseVal)) {
if (C1->getType() == C2->getType() && ~C1->getValue() == C2->getValue() &&
(match(TrueVal, m_Not(m_Specific(CmpLHS))) ||
match(CmpLHS, m_Not(m_Specific(TrueVal))))) {
LHS = TrueVal;
RHS = FalseVal;
return {SPF_SMIN, SPNB_NA, false};
}
}
}
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20151204/5b6631f8/attachment.html>
More information about the llvm-bugs
mailing list