Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
Show First 20 Lines • Show All 2,676 Lines • ▼ Show 20 Lines | if (*Res == true) { | ||||
else | else | ||||
// select op, true, (select cond, A, B) => select op, true, B | // select op, true, (select cond, A, B) => select op, true, B | ||||
// or op, (select cond, A, B) => select op, true, B | // or op, (select cond, A, B) => select op, true, B | ||||
// if op = false implies condval = false. | // if op = false implies condval = false. | ||||
return SelectInst::Create(Op, One, B); | return SelectInst::Create(Op, One, B); | ||||
} | } | ||||
} | } | ||||
static FastMathFlags getFMFforSel(SelectInst &SI) { | |||||
Value *TrueVal = SI.getTrueValue(); | |||||
Value *FalseVal = SI.getFalseValue(); | |||||
FastMathFlags FMF; | |||||
FMF.set(); | |||||
if (auto *V = dyn_cast<FPMathOperator>(TrueVal)) | |||||
FMF &= V->getFastMathFlags(); | |||||
else | |||||
FMF &= FastMathFlags::getFromFuncAttr(SI.getFunction()); | |||||
if (auto *V = dyn_cast<FPMathOperator>(FalseVal)) | |||||
FMF &= V->getFastMathFlags(); | |||||
else | |||||
FMF &= FastMathFlags::getFromFuncAttr(SI.getFunction()); | |||||
// This is probably not needed. | |||||
// Value *CondVal = SI.getCondition(); | |||||
// if (auto *V = dyn_cast<FPMathOperator>(CondVal)) | |||||
// FMF &= V->getFastMathFlags(); | |||||
// else | |||||
// FMF &= FastMathFlags::getFromFuncAttr(SI.getFunction()); | |||||
return FMF; | |||||
} | |||||
Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) { | Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) { | ||||
Value *CondVal = SI.getCondition(); | Value *CondVal = SI.getCondition(); | ||||
Value *TrueVal = SI.getTrueValue(); | Value *TrueVal = SI.getTrueValue(); | ||||
Value *FalseVal = SI.getFalseValue(); | Value *FalseVal = SI.getFalseValue(); | ||||
Type *SelType = SI.getType(); | Type *SelType = SI.getType(); | ||||
// FIXME: Remove this workaround when freeze related patches are done. | // FIXME: Remove this workaround when freeze related patches are done. | ||||
// For select with undef operand which feeds into an equality comparison, | // For select with undef operand which feeds into an equality comparison, | ||||
Show All 16 Lines | if (Value *V = SimplifySelectInst(CondVal, TrueVal, FalseVal, | ||||
return replaceInstUsesWith(SI, V); | return replaceInstUsesWith(SI, V); | ||||
if (Instruction *I = canonicalizeSelectToShuffle(SI)) | if (Instruction *I = canonicalizeSelectToShuffle(SI)) | ||||
return I; | return I; | ||||
if (Instruction *I = canonicalizeScalarSelectOfVecs(SI, *this)) | if (Instruction *I = canonicalizeScalarSelectOfVecs(SI, *this)) | ||||
return I; | return I; | ||||
// If the select does not have any FMFs then use the intersection | |||||
// of it's operand's FMFs. | |||||
if (isa<FPMathOperator>(SI) && SI.getFastMathFlags().none()) { | |||||
FastMathFlags FMF = getFMFforSel(SI); | |||||
if (FMF.any()) { | |||||
SI.setFastMathFlags(getFMFforSel(SI)); | |||||
return &SI; | |||||
} | |||||
} | |||||
CmpInst::Predicate Pred; | CmpInst::Predicate Pred; | ||||
// Avoid potential infinite loops by checking for non-constant condition. | // Avoid potential infinite loops by checking for non-constant condition. | ||||
// TODO: Can we assert instead by improving canonicalizeSelectToShuffle()? | // TODO: Can we assert instead by improving canonicalizeSelectToShuffle()? | ||||
// Scalar select must have simplified? | // Scalar select must have simplified? | ||||
if (SelType->isIntOrIntVectorTy(1) && !isa<Constant>(CondVal) && | if (SelType->isIntOrIntVectorTy(1) && !isa<Constant>(CondVal) && | ||||
TrueVal->getType() == CondVal->getType()) { | TrueVal->getType() == CondVal->getType()) { | ||||
// Folding select to and/or i1 isn't poison safe in general. impliesPoison | // Folding select to and/or i1 isn't poison safe in general. impliesPoison | ||||
▲ Show 20 Lines • Show All 592 Lines • Show Last 20 Lines |