[PATCH] D149374: [LICM] Hoist widenable condition when it's the only non-invariant operand of its user

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 27 21:39:26 PDT 2023


mkazantsev added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/LICM.cpp:1240
 
+    if (match(CI, m_Intrinsic<Intrinsic::experimental_widenable_condition>())) {
+      // Hoist widenable condition when it's the only non-invariant operand of
----------------
Imagine case:
Test 1:

```
c1 = load // can be hoisted
wc = call widenable_condition()
and = c1 & wc
```
Test 2:
```
wc = call widenable_condition()
c1 = load // can be hoisted
and = c1 & wc
```


If `c1` is processed first and gets hoisted, then you also hoist `wc` and then `and`. But if `wc` is processed first, `c1` is not yet made invariant, then you don't hoist neither `wc` nor `and`. I think you can construct a test demonstrating that by just putting `wc` ahead of `c1`.

The right solution would be to handle this when processing the user of `wc` (in this case it is `and`). If all of instruction's operands that are not loop-invariant are single-use widenable conditions, then all of them can be hoisted together with the `and`. In this case, you have a guarantee that everything that is not `wc` and that is hoistable has already been hoisted.


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

https://reviews.llvm.org/D149374



More information about the llvm-commits mailing list