[PATCH] D108408: [InstCombine] Transform X == 0 ? 0 : X * Y --> X * freeze(Y).

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 10 13:44:57 PDT 2021


nikic added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:768
+
+  auto *FalseValI = cast<Instruction>(FalseVal);
+  auto *FrY = new FreezeInst(Y, Y->getName() + ".fr", FalseValI);
----------------
I believe this may fail if the multiplication is a constant expression (we should bail in that case).


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:769
+  auto *FalseValI = cast<Instruction>(FalseVal);
+  auto *FrY = new FreezeInst(Y, Y->getName() + ".fr", FalseValI);
+  IC.replaceOperand(*FalseValI, FalseValI->getOperand(0) == Y ? 0 : 1, FrY);
----------------
It would be better to create the freeze using IRBuilder, because it will be queued for reprocessing that way. Or alternatively using `InsertNewInstBefore`, which also handles this correctly.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108408/new/

https://reviews.llvm.org/D108408



More information about the llvm-commits mailing list