Issue 156464
Summary VPExpressionRecipe discards duplicate recipes.
Labels vectorizers, crash-on-valid
Assignees
Reporter SamTebbs33
    The `VPExpressionRecipe` class takes two extend recipes and a multiply recipe and bundles them into one so that the cost of the extends and multiply are hidden from the cost model. However, it uses a set to store these recipes and so any duplicates are discarded, meaning any attempt to use those recipes for cost computation or printing causes an error.

```; opt -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -prefer-inloop-reductions --debug-_only_=loop-vectorize
define i64 @print_mulacc_extended(ptr nocapture readonly %x, ptr nocapture readonly %y, i32 %n) {
entry:
  br label %loop

loop:
  %iv = phi i32 [ %iv.next, %loop ], [ 0, %entry ]
  %rdx = phi i64 [ %rdx.next, %loop ], [ 0, %entry ]
  %arrayidx = getelementptr inbounds i16, ptr %x, i32 %iv
  %load0 = load i16, ptr %arrayidx, align 4
 %arrayidx1 = getelementptr inbounds i16, ptr %y, i32 %iv
  %load1 = load i16, ptr %arrayidx1, align 4
  %conv0 = sext i16 %load0 to i32
  %conv1 = sext i16 %load1 to i32
  %mul = mul nsw i32 %conv0, %conv0
  %conv = sext i32 %mul to i64
  %rdx.next = add nsw i64 %rdx, %conv
  %iv.next = add nuw nsw i32 %iv, 1
  %exitcond = icmp eq i32 %iv.next, %n
  br i1 %exitcond, label %exit, label %loop

exit:
  %r.0.lcssa = phi i64 [ %rdx.next, %loop ]
  ret i64 %r.0.lcssa
}
```
causes
```[...]
<x1> vector loop: {
 vector.body:
    EMIT vp<%4> = CANONICAL-INDUCTION ir<0>, vp<%index.next>
 WIDEN-REDUCTION-PHI ir<%rdx> = phi vp<%3>, vp<%7>
    vp<%5> = SCALAR-STEPS vp<%4>, ir<1>, vp<%0>
    CLONE ir<%arrayidx> = getelementptr inbounds ir<%x>, vp<%5>
    vp<%6> = vector-pointer ir<%arrayidx>
    WIDEN ir<%load0> = load vp<%6>
    _expression_ vp<%7> = ir<%rdx> + reduce.add (mulopt: /home/work/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = VPWidenRecipe; From = VPSingleDefRecipe]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
```
The recipe list should contain the two extends, the mul and the reduction, but since duplicates are discarded, it's only one extend, the mul and reduction. The printing code attempts to access the mul from `ExpressionRecipes[2]`, where it should be, but that is actually the reduction.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to