// resulting list of subconditions in Checks vector.
SmallVector<Value *, 4> Worklist(1, Condition);
SmallPtrSet<Value *, 4> Visited;
+ Value *WideableCond = nullptr;
do {
Value *Condition = Worklist.pop_back_val();
if (!Visited.insert(Condition).second)
continue;
}
+ if (match(Condition,
+ m_Intrinsic<Intrinsic::experimental_widenable_condition>())) {
+ // Pick any, we don't care which
+ WideableCond = Condition;
+ continue;
+ }
+
if (ICmpInst *ICI = dyn_cast<ICmpInst>(Condition)) {
if (auto NewRangeCheck = widenICmpRangeCheck(ICI, Expander,
Builder)) {
// Save the condition as is if we can't widen it
Checks.push_back(Condition);
} while (!Worklist.empty());
+ // At the moment, our matching logic for wideable conditions implicitly
+ // assumes we preserve the form: (br (and Cond, WC())). FIXME
+ // Note that if there were multiple calls to wideable condition in the
+ // traversal, we only need to keep one, and which one is arbitrary.
+ if (WideableCond)
+ Checks.push_back(WideableCond);
return NumWidened;
}
TotalConsidered++;
SmallVector<Value *, 4> Checks;
IRBuilder<> Builder(cast<Instruction>(Preheader->getTerminator()));
- Value *Condition = nullptr, *WidenableCondition = nullptr;
- BasicBlock *GBB = nullptr, *DBB = nullptr;
- parseWidenableBranch(BI, Condition, WidenableCondition, GBB, DBB);
- unsigned NumWidened = collectChecks(Checks, Condition, Expander, Builder);
+ unsigned NumWidened = collectChecks(Checks, BI->getCondition(),
+ Expander, Builder);
if (NumWidened == 0)
return false;
LastCheck = Check;
else
LastCheck = Builder.CreateAnd(LastCheck, Check);
- // Make sure that the check contains widenable condition and therefore can be
- // further widened.
- LastCheck = Builder.CreateAnd(LastCheck, WidenableCondition);
- auto *OldCond = BI->getOperand(0);
- BI->setOperand(0, LastCheck);
+ auto *OldCond = BI->getCondition();
+ BI->setCondition(LastCheck);
assert(isGuardAsWidenableBranch(BI) &&
"Stopped being a guard after transform?");
RecursivelyDeleteTriviallyDeadInstructions(OldCond);