Skip to content

[GVN][NFC] Match coding standards #128683

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

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 39 additions & 39 deletions llvm/lib/Transforms/Scalar/GVN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,98 +332,98 @@ struct llvm::gvn::AvailableValueInBlock {
//===----------------------------------------------------------------------===//

GVNPass::Expression GVNPass::ValueTable::createExpr(Instruction *I) {
Expression e;
e.type = I->getType();
e.opcode = I->getOpcode();
Expression E;
E.type = I->getType();
E.opcode = I->getOpcode();
if (const GCRelocateInst *GCR = dyn_cast<GCRelocateInst>(I)) {
// gc.relocate is 'special' call: its second and third operands are
// not real values, but indices into statepoint's argument list.
// Use the refered to values for purposes of identity.
e.varargs.push_back(lookupOrAdd(GCR->getOperand(0)));
e.varargs.push_back(lookupOrAdd(GCR->getBasePtr()));
e.varargs.push_back(lookupOrAdd(GCR->getDerivedPtr()));
E.varargs.push_back(lookupOrAdd(GCR->getOperand(0)));
E.varargs.push_back(lookupOrAdd(GCR->getBasePtr()));
E.varargs.push_back(lookupOrAdd(GCR->getDerivedPtr()));
} else {
for (Use &Op : I->operands())
e.varargs.push_back(lookupOrAdd(Op));
E.varargs.push_back(lookupOrAdd(Op));
}
if (I->isCommutative()) {
// Ensure that commutative instructions that only differ by a permutation
// of their operands get the same value number by sorting the operand value
// numbers. Since commutative operands are the 1st two operands it is more
// efficient to sort by hand rather than using, say, std::sort.
assert(I->getNumOperands() >= 2 && "Unsupported commutative instruction!");
if (e.varargs[0] > e.varargs[1])
std::swap(e.varargs[0], e.varargs[1]);
e.commutative = true;
if (E.varargs[0] > E.varargs[1])
std::swap(E.varargs[0], E.varargs[1]);
E.commutative = true;
}

if (auto *C = dyn_cast<CmpInst>(I)) {
// Sort the operand value numbers so x<y and y>x get the same value number.
CmpInst::Predicate Predicate = C->getPredicate();
if (e.varargs[0] > e.varargs[1]) {
std::swap(e.varargs[0], e.varargs[1]);
if (E.varargs[0] > E.varargs[1]) {
std::swap(E.varargs[0], E.varargs[1]);
Predicate = CmpInst::getSwappedPredicate(Predicate);
}
e.opcode = (C->getOpcode() << 8) | Predicate;
e.commutative = true;
} else if (auto *E = dyn_cast<InsertValueInst>(I)) {
e.varargs.append(E->idx_begin(), E->idx_end());
E.opcode = (C->getOpcode() << 8) | Predicate;
E.commutative = true;
} else if (auto *IVI = dyn_cast<InsertValueInst>(I)) {
E.varargs.append(IVI->idx_begin(), IVI->idx_end());
} else if (auto *SVI = dyn_cast<ShuffleVectorInst>(I)) {
ArrayRef<int> ShuffleMask = SVI->getShuffleMask();
e.varargs.append(ShuffleMask.begin(), ShuffleMask.end());
E.varargs.append(ShuffleMask.begin(), ShuffleMask.end());
} else if (auto *CB = dyn_cast<CallBase>(I)) {
e.attrs = CB->getAttributes();
E.attrs = CB->getAttributes();
}

return e;
return E;
}

GVNPass::Expression GVNPass::ValueTable::createCmpExpr(
unsigned Opcode, CmpInst::Predicate Predicate, Value *LHS, Value *RHS) {
assert((Opcode == Instruction::ICmp || Opcode == Instruction::FCmp) &&
"Not a comparison!");
Expression e;
e.type = CmpInst::makeCmpResultType(LHS->getType());
e.varargs.push_back(lookupOrAdd(LHS));
e.varargs.push_back(lookupOrAdd(RHS));
Expression E;
E.type = CmpInst::makeCmpResultType(LHS->getType());
E.varargs.push_back(lookupOrAdd(LHS));
E.varargs.push_back(lookupOrAdd(RHS));

// Sort the operand value numbers so x<y and y>x get the same value number.
if (e.varargs[0] > e.varargs[1]) {
std::swap(e.varargs[0], e.varargs[1]);
if (E.varargs[0] > E.varargs[1]) {
std::swap(E.varargs[0], E.varargs[1]);
Predicate = CmpInst::getSwappedPredicate(Predicate);
}
e.opcode = (Opcode << 8) | Predicate;
e.commutative = true;
return e;
E.opcode = (Opcode << 8) | Predicate;
E.commutative = true;
return E;
}

GVNPass::Expression
GVNPass::ValueTable::createExtractvalueExpr(ExtractValueInst *EI) {
assert(EI && "Not an ExtractValueInst?");
Expression e;
e.type = EI->getType();
e.opcode = 0;
Expression E;
E.type = EI->getType();
E.opcode = 0;

WithOverflowInst *WO = dyn_cast<WithOverflowInst>(EI->getAggregateOperand());
if (WO != nullptr && EI->getNumIndices() == 1 && *EI->idx_begin() == 0) {
// EI is an extract from one of our with.overflow intrinsics. Synthesize
// a semantically equivalent expression instead of an extract value
// expression.
e.opcode = WO->getBinaryOp();
e.varargs.push_back(lookupOrAdd(WO->getLHS()));
e.varargs.push_back(lookupOrAdd(WO->getRHS()));
return e;
E.opcode = WO->getBinaryOp();
E.varargs.push_back(lookupOrAdd(WO->getLHS()));
E.varargs.push_back(lookupOrAdd(WO->getRHS()));
return E;
}

// Not a recognised intrinsic. Fall back to producing an extract value
// expression.
e.opcode = EI->getOpcode();
E.opcode = EI->getOpcode();
for (Use &Op : EI->operands())
e.varargs.push_back(lookupOrAdd(Op));
E.varargs.push_back(lookupOrAdd(Op));

append_range(e.varargs, EI->indices());
append_range(E.varargs, EI->indices());

return e;
return E;
}

GVNPass::Expression GVNPass::ValueTable::createGEPExpr(GetElementPtrInst *GEP) {
Expand Down