[PATCH] D70148: [SLP] fix miscompile on min/max reductions with extra uses (PR43948)

Alexey Bataev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 13 07:04:38 PST 2019


ABataev added inline comments.


================
Comment at: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:6744-6753
+      Instruction *RdxCmp, *Cmp;
+      if (match(cast<Instruction>(ReductionRoot),
+                m_Select(m_Instruction(RdxCmp), m_Value(), m_Value())) &&
+          (RdxCmp->getOpcode() == Instruction::ICmp ||
+           RdxCmp->getOpcode() == Instruction::FCmp) &&
+          match(VectorizedTree,
+                m_Select(m_Instruction(Cmp), m_Value(), m_Value())) &&
----------------
I don't think you need matches here. You can rely on `ReductionData.getKind()` and then just do something like this:
```
switch (ReductionData.getKind()) {
case RK_Min:
case RK_Max:
case RK_UMin:
case RK_UMax:
  cast<SelectInstruction>(ReductionRoot)->getCondition()->replaceAllUsesWith(cast<SelectInstruction>(VectorizedTree)->getCondition());
  break;
case RK_Arithmetic:
  break;
}
```
And even better to create a new member function in Operation data, which will replace all uses for the vectorized instruction like in this code + the final replacement.


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

https://reviews.llvm.org/D70148





More information about the llvm-commits mailing list