[PATCH] D115268: [SLP]Fix comparator for cmp instruction vectorization.

Alexey Bataev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 8 04:42:39 PST 2021


ABataev added inline comments.


================
Comment at: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:9541
+      for (int I = 0, E = CI1->getNumOperands(); I < E; ++I) {
+        auto *Op0 = CI1->getOperand(Pred1 <= Pred2 ? I : E - I - 1);
+        auto *Op1 = CI2->getOperand(Pred1 >= Pred2 ? I : E - I - 1);
----------------
ABataev wrote:
> vporpo wrote:
> > If I understand correctly, at this point the predicates are either equal or opposites. You comparing them like `Pred1 <= Pred2` and `Pred1 >= Pred2`, which I think is equivalent to something like:
> > ```
> > bool PredsAreOpposite = Pred1 != Pred2;
> > for (int I = 0, E = CI1->getNumOperands(); I < E; ++I) {
> >   auto *Op0 = CI1->getOperand(I);
> >   auto *Op1 = CI2->getOperand(!PredAreOpposite ? I : E - I - 1);
> > ```
> > I think this is what you did in line 9576 below.
> > 
> Yes, but in this form, it does not meet the criterion again for some cases, tried it. The provided form provides strict weak ordering.
It does not work for these 2 cmp instructions: `icmp slt 0, x` and `icmp sgt x, 0` (`x` is an instruction). Compare returns true for compare(v1, v2) and compare(v2, v1) and thus does not meet the requirement for the weak strict ordering.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115268



More information about the llvm-commits mailing list