[PATCH] D139339: [InstCombine] Bubble vector.reverse of select operands to their result.

David Sherwood via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 6 02:29:32 PST 2022


david-arm added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:2340
+      if (auto *I = dyn_cast<Instruction>(V))
+        I->copyIRFlags(&Sel);
+      Module *M = Sel.getModule();
----------------
Would it be possible to modify one of the existing tests to have flags so we can correctly defend their propagation? We now have code paths where we depend upon the fast-math flags being set correctly on the select by the loop vectoriser.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:2354
+      // select rev(C), rev(X), YSplat --> rev(select C, X, FValSplat)
+      if ((Cond->hasOneUse() || TVal->hasOneUse()) && isSplatValue(FVal))
+        return createSelReverse(C, X, FVal);
----------------
I don't know how far you want to go with this, but you can support more than just splats for the false and true vals. For example, we can also do the transformation when FVal is an arbitrary fixed-width vector constant, i.e.

```define <4 x i32> @select_reverse(<4 x i1> %a, <4 x i32> %b, <4 x i32> %c) {
  %a.rev = tail call <4 x i1> @llvm.experimental.vector.reverse.v4i1(<4 x i1> %a)
  %b.rev = tail call <4 x i32> @llvm.experimental.vector.reverse.v4i32(<4 x i32> %b)
  %select = select <4 x i1> %a.rev, <4 x i32> %b.rev, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
  ret <4 x i32> %select
}```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139339



More information about the llvm-commits mailing list