-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[InstCombine] Simplify phi using KnownBits of condition #134712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1625,6 +1625,44 @@ Instruction *InstCombinerImpl::visitPHINode(PHINode &PN) { | |||||||||||||||
return replaceInstUsesWith(PN, &IdenticalPN); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
if (PN.getType()->isIntegerTy()) { | ||||||||||||||||
BasicBlock *PNBB = PN.getParent(); | ||||||||||||||||
KnownBits Known(PN.getType()->getScalarSizeInBits()); | ||||||||||||||||
bool MadeChange = false; | ||||||||||||||||
for (unsigned I = 0, E = PN.getNumIncomingValues(); I != E; ++I) { | ||||||||||||||||
Value *V = PN.getIncomingValue(I); | ||||||||||||||||
if (isa<ConstantInt>(V)) | ||||||||||||||||
continue; | ||||||||||||||||
|
||||||||||||||||
ArrayRef<BranchInst *> BRs = SQ.DC->conditionsFor(V); | ||||||||||||||||
if (BRs.empty()) | ||||||||||||||||
continue; | ||||||||||||||||
|
||||||||||||||||
Known.resetAll(); | ||||||||||||||||
Instruction *CtxI = PN.getIncomingBlock(I)->getTerminator(); | ||||||||||||||||
SimplifyQuery Q = SQ.getWithInstruction(CtxI); | ||||||||||||||||
BranchInst *BI = dyn_cast<BranchInst>(CtxI); | ||||||||||||||||
if (BI && BI->isConditional() && llvm::is_contained(BRs, BI)) { | ||||||||||||||||
CondContext CC(BI->getCondition()); | ||||||||||||||||
CC.AffectedValues.insert(V); | ||||||||||||||||
if (BI->getSuccessor(1) == PNBB) | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assumed that the two branched did not have the same label but found this llvm-project/llvm/lib/Analysis/ValueTracking.cpp Lines 1735 to 1736 in 72436b3
But I'm not able to create a test that have the same label for the two branches https://godbolt.org/z/avb161nYe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://godbolt.org/z/vacTYPoha is the way to spell it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the help with how to make the test. llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp Lines 3787 to 3791 in 72436b3
|
||||||||||||||||
CC.Invert = true; | ||||||||||||||||
llvm::computeKnownBits(V, Known, /* Depth */ 0, | ||||||||||||||||
Q.getWithCondContext(CC)); | ||||||||||||||||
} else { | ||||||||||||||||
llvm::computeKnownBits(V, Known, /* Depth */ 0, Q); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
if (Known.isConstant()) { | ||||||||||||||||
replaceOperand(PN, I, | ||||||||||||||||
ConstantInt::get(V->getType(), Known.getConstant())); | ||||||||||||||||
MadeChange = true; | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
if (MadeChange) | ||||||||||||||||
return &PN; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// If this is an integer PHI and we know that it has an illegal type, see if | ||||||||||||||||
// it is only used by trunc or trunc(lshr) operations. If so, we split the | ||||||||||||||||
// PHI into the various pieces being extracted. This sort of thing is | ||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.