[PATCH] D103661: [IR] Add utility to convert constant expression operands (of an instruction) to instructions.
Stanislav Mekhanoshin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 4 14:37:23 PDT 2021
rampitec added inline comments.
================
Comment at: llvm/lib/IR/ReplaceConstant.cpp:107
+
+ if (CE->getNumOperands()) {
+ SmallPtrSet<Value *, 4> Operands2;
----------------
To address Jay's comment I think you can pass an original CE into this function and amend the if to only execute it if CE != ReplacedCE. It will then skip the operands of the expression being replaced itself. I.e.:
```
@@ -77,12 +77,13 @@ void convertConstantExprsToInstructions(Instruction *I, ConstantExpr *CE,
// Convert constant expressions operands of I (from the set CEOperands) to
// instructions.
- convertConstantExprsToInstructions(I, CEOperands, Insts);
+ convertConstantExprsToInstructions(I, CEOperands, Insts, CE);
}
void convertConstantExprsToInstructions(Instruction *I,
SmallPtrSetImpl<Value *> &Operands,
- SmallPtrSetImpl<Instruction *> &Insts) {
+ SmallPtrSetImpl<Instruction *> &Insts,
+ ConstantExpr *C) {
for (Use &U : I->operands()) {
auto *V = U.get();
@@ -104,11 +105,9 @@ void convertConstantExprsToInstructions(Instruction *I,
I->replaceUsesOfWith(CE, NI);
Insts.insert(NI);
- if (CE->getNumOperands()) {
+ if (C != CE && CE->getNumOperands()) {
SmallPtrSet<Value *, 4> Operands2;
for (Use &UU : CE->operands())
Operands2.insert(UU.get());
- convertConstantExprsToInstructions(NI, Operands2, Insts);
+ convertConstantExprsToInstructions(NI, Operands2, Insts, C);
}
CE->removeDeadConstantUsers();
```
Note there are never recursive constant expressions.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D103661/new/
https://reviews.llvm.org/D103661
More information about the llvm-commits
mailing list