Skip to content

Commit 0f3c655

Browse files
committed
Address comments
1 parent 1d56b80 commit 0f3c655

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -511,16 +511,16 @@ class XorToOrDisjointTransformer {
511511
const DataLayout &DL;
512512
/// Maps a common operand to all Xor instructions
513513
using XorOpList = SmallVector<std::pair<BinaryOperator *, APInt>, 8>;
514-
using XorBaseValMap = DenseMap<Value *, XorOpList>;
515-
XorBaseValMap XorGroups;
514+
using XorBaseValInst = DenseMap<Instruction *, XorOpList>;
515+
XorBaseValInst XorGroups;
516516

517517
/// Checks if the given value has at least one GetElementPtr user
518-
bool hasGEPUser(const Value *V) const;
518+
static bool hasGEPUser(const Value *V);
519519

520520
/// Processes a group of XOR instructions that share the same non-constant
521521
/// base operand. Returns true if this group's processing modified the
522522
/// function.
523-
bool processXorGroup(Value *OriginalBaseVal, XorOpList &XorsInGroup);
523+
bool processXorGroup(Instruction *OriginalBaseInst, XorOpList &XorsInGroup);
524524
};
525525

526526
} // end anonymous namespace
@@ -1200,7 +1200,7 @@ bool SeparateConstOffsetFromGEP::splitGEP(GetElementPtrInst *GEP) {
12001200
}
12011201

12021202
// Helper function to check if an instruction has at least one GEP user
1203-
bool XorToOrDisjointTransformer::hasGEPUser(const Value *V) const {
1203+
bool XorToOrDisjointTransformer::hasGEPUser(const Value *V) {
12041204
for (const User *U : V->users()) {
12051205
if (isa<GetElementPtrInst>(U)) {
12061206
return true;
@@ -1209,7 +1209,7 @@ bool XorToOrDisjointTransformer::hasGEPUser(const Value *V) const {
12091209
return false;
12101210
}
12111211

1212-
bool XorToOrDisjointTransformer::processXorGroup(Value *OriginalBaseVal,
1212+
bool XorToOrDisjointTransformer::processXorGroup(Instruction *OriginalBaseInst,
12131213
XorOpList &XorsInGroup) {
12141214
bool Changed = false;
12151215
if (XorsInGroup.size() <= 1)
@@ -1241,7 +1241,7 @@ bool XorToOrDisjointTransformer::processXorGroup(Value *OriginalBaseVal,
12411241
BinaryOperator *ClonedXor =
12421242
cast<BinaryOperator>(XorWithSmallConst->clone());
12431243
ClonedXor->setName(XorWithSmallConst->getName() + ".dom_clone");
1244-
ClonedXor->insertAfter(dyn_cast<Instruction>(OriginalBaseVal));
1244+
ClonedXor->insertAfter(OriginalBaseInst);
12451245
LLVM_DEBUG(dbgs() << " Cloned Inst: " << *ClonedXor << "\n");
12461246
Changed = true;
12471247
XorWithSmallConst = ClonedXor;
@@ -1251,7 +1251,7 @@ bool XorToOrDisjointTransformer::processXorGroup(Value *OriginalBaseVal,
12511251

12521252
SmallVector<Instruction *, 8> InstructionsToErase;
12531253
const APInt SmallestConst =
1254-
dyn_cast<ConstantInt>(XorWithSmallConst->getOperand(1))->getValue();
1254+
cast<ConstantInt>(XorWithSmallConst->getOperand(1))->getValue();
12551255

12561256
// Main transformation loop: Iterate over the original XORs in the sorted
12571257
// group.
@@ -1289,7 +1289,7 @@ bool XorToOrDisjointTransformer::processXorGroup(Value *OriginalBaseVal,
12891289

12901290
auto *NewOrInst = BinaryOperator::CreateDisjointOr(
12911291
XorWithSmallConst,
1292-
ConstantInt::get(OriginalBaseVal->getType(), NewConstVal),
1292+
ConstantInt::get(OriginalBaseInst->getType(), NewConstVal),
12931293
XorInst->getName() + ".or_disjoint", XorInst->getIterator());
12941294

12951295
NewOrInst->copyMetadata(*XorInst);
@@ -1308,9 +1308,9 @@ bool XorToOrDisjointTransformer::processXorGroup(Value *OriginalBaseVal,
13081308
<< " New Const: " << NewConstVal << "\n");
13091309
}
13101310
}
1311-
if (!InstructionsToErase.empty())
1312-
for (Instruction *I : InstructionsToErase)
1313-
I->eraseFromParent();
1311+
1312+
for (Instruction *I : InstructionsToErase)
1313+
I->eraseFromParent();
13141314

13151315
return Changed;
13161316
}
@@ -1335,9 +1335,11 @@ bool XorToOrDisjointTransformer::run() {
13351335
Value *Op0 = XorOp->getOperand(0);
13361336
ConstantInt *C1 = nullptr;
13371337
// Match: xor Op0, Constant
1338-
if (match(XorOp->getOperand(1), m_ConstantInt(C1))) {
1338+
if (isa<Instruction>(Op0) &&
1339+
match(XorOp->getOperand(1), m_ConstantInt(C1))) {
13391340
if (hasGEPUser(XorOp)) {
1340-
XorGroups[Op0].push_back({XorOp, C1->getValue()});
1341+
Instruction *InstOp0 = cast<Instruction>(Op0);
1342+
XorGroups[InstOp0].push_back({XorOp, C1->getValue()});
13411343
}
13421344
}
13431345
}
@@ -1349,9 +1351,9 @@ bool XorToOrDisjointTransformer::run() {
13491351

13501352
// Process each group of XORs
13511353
for (auto &GroupPair : XorGroups) {
1352-
Value *OriginalBaseVal = GroupPair.first;
1354+
Instruction *OriginalBaseInst = cast<Instruction>(GroupPair.first);
13531355
XorOpList &XorsInGroup = GroupPair.second;
1354-
if (processXorGroup(OriginalBaseVal, XorsInGroup))
1356+
if (processXorGroup(OriginalBaseInst, XorsInGroup))
13551357
Changed = true;
13561358
}
13571359

0 commit comments

Comments
 (0)