[PATCH] D131672: [instcombine] Optimise for zero initialisation of product given finite math in Clang

Zain Jaffal via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 15 03:02:59 PDT 2022


zjaffal added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp:1476
+  if (phiAllConstantOperandsAreZero(PN)) {
+    for (Value *Operands : PN.operands()) {
+      if (Instruction *Fmul = dyn_cast<Instruction>(Operands)) {
----------------
spatel wrote:
> Can we use llvm::matchSimpleRecurrence()?
> 
> Here's an example usage within instcombine:
> https://github.com/llvm/llvm-project/blob/1828c75d5f4ff657cf977476091fa224c8193e1d/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp#L2201
I tested using `llvm::matchSimpleRecurrence`. Here is what I found

1. We need to move the optimisation into `InstCombineMulDivRem` instead which is fine. 
2. We need to add a case into `llvm::matchSimpleRecurrence` to handle `FMul` 
3. The main issue of using matchSimpleRecurrence is that it doesn't handle `phi` with more than two operands. 

I am not sure how common phi's with more than two operands are. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131672



More information about the llvm-commits mailing list