[PATCH] D123720: [VPlan] Replace use of needsVectorIV with VPlan user check.

Bardia Mahjour via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 22 12:17:50 PDT 2022


bmahjour added a comment.

Hi @fhahn , this looks like a regression from your commit below:

  commit cedfd7a2e536d2ff6da44e89a024baa402dc3e58
  Author: Florian Hahn <flo at fhahn.com>
  Date:   Wed Jun 8 14:06:45 2022 +0100
  
      Recommit "[VPlan] Remove uneeded needsVectorIV check."
  
      This reverts commit 266ea446ab747671eb6c736569c3c9c5f3c53d11.
  
      The reasons for the revert have been addressed by cleaning up condition
      handling in VPlan and properly marking VPBranchOnMaskRecipe as using
      scalars.
  
      The test case for the revert from D123720 has been added in 3d663308a5d.

Last good commit is `98d4f0651a7f90df161167362e2060e0b4de7969`. Could you please have a look?

  > cat red3.c
  int foo(float *p, int n)
  {
    int count = 0, prev = 0;
    for (int i = 0; i < n; i++) {
      if (p[prev] < 0)
        count++;
      prev = i;
    }
    return count;
  }

  clang -mcpu=pwr10 -O2 -fprofile-generate -c red3.c -target "powerpc-ibm-aix7.2.0.0"

or reproduce with the attached IR using:F23548492: input.ll <https://reviews.llvm.org/F23548492>

  opt -passes=loop-vectorize input.ll -S -o out.ll -debug-only=loop-vectorize
  ...
  LoopVectorize.cpp:9434: virtual void llvm::VPWidenIntOrFpInductionRecipe::execute(llvm::VPTransformState &): Assertion `State.VF.isVector() && "must have vector VF"' failed.
  PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
  Stack dump:
  0.      Program arguments: /home/bmahjour/workspaces/wyvern_all/upstream-fork/build/bin/opt -passes=loop-vectorize input.ll -S -o out.ll -debug-only=loop-vectorize
   #0 0x0000000012ea7414 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/bmahjour/workspaces/wyvern_all/upstream-fork/build/bin/opt+0x12ea7414)
   #1 0x0000000012ea7834 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
   #2 0x0000000012ea4558 llvm::sys::RunSignalHandlers() (/home/bmahjour/workspaces/wyvern_all/upstream-fork/build/bin/opt+0x12ea4558)
   #3 0x0000000012ea7afc SignalHandler(int) Signals.cpp:0:0
   #4 0x00002000000604c8 (linux-vdso64.so.1+0x4c8)
   #5 0x000020000064d168 __libc_signal_restore_set /build/glibc-E31xyL/glibc-2.31/signal/../sysdeps/unix/sysv/linux/internal-signals.h:86:3
   #6 0x000020000064d168 raise /build/glibc-E31xyL/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:48:3
   #7 0x0000200000624850 abort /build/glibc-E31xyL/glibc-2.31/stdlib/abort.c:79:7
   #8 0x000020000063c49c __assert_fail_base /build/glibc-E31xyL/glibc-2.31/assert/assert.c:92:3
   #9 0x000020000063c540 __assert_fail /build/glibc-E31xyL/glibc-2.31/assert/assert.c:101:3
  #10 0x00000000130df418 llvm::VPWidenIntOrFpInductionRecipe::execute(llvm::VPTransformState&) (/home/bmahjour/workspaces/wyvern_all/upstream-fork/build/bin/opt+0x130df418)
  #11 0x00000000131abd6c llvm::VPBasicBlock::execute(llvm::VPTransformState*) (/home/bmahjour/workspaces/wyvern_all/upstream-fork/build/bin/opt+0x131abd6c)
  #12 0x00000000131ad898 llvm::VPRegionBlock::execute(llvm::VPTransformState*) (/home/bmahjour/workspaces/wyvern_all/upstream-fork/build/bin/opt+0x131ad898)
  #13 0x00000000131b1188 llvm::VPlan::execute(llvm::VPTransformState*) (/home/bmahjour/workspaces/wyvern_all/upstream-fork/build/bin/opt+0x131b1188)
  #14 0x00000000130ce954 llvm::LoopVectorizationPlanner::executePlan(llvm::ElementCount, unsigned int, llvm::VPlan&, llvm::InnerLoopVectorizer&, llvm::DominatorTree*) (/home/bmahjour/workspaces/wyvern_all/upstream-fork/build/bin/opt+0x130ce954)

Looks like we try to vectorize by VF=1 UF=8, but the VPlan has a widen-induction recipe:

  VPlan 'Initial VPlan for VF={1},UF>=1' {
  Live-in vp<%1> = vector-trip-count
  
  vector.ph:
  Successor(s): vector loop
  
  <x1> vector loop: {
    vector.body:
      EMIT vp<%2> = CANONICAL-INDUCTION
      FIRST-ORDER-RECURRENCE-PHI ir<%prev.011> = phi ir<0>, ir<%indvars15>
      WIDEN-REDUCTION-PHI ir<%count.010> = phi ir<0>, ir<%count.1>
      WIDEN-INDUCTION\l" +
      "  %pgocount1314 = phi %5, 0\l" +
      "  ir<%indvars15>, ir<1>
      EMIT vp<%6> = first-order splice ir<%prev.011> ir<%indvars15>
      CLONE ir<%arrayidx> = getelementptr ir<%p>, vp<%6>
      CLONE ir<%6> = load ir<%arrayidx>
      CLONE ir<%cmp1> = fcmp ir<%6>, ir<0.000000e+00>
      CLONE ir<%inc> = zext ir<%cmp1>
      CLONE ir<%count.1> = add ir<%count.010>, ir<%inc>
      EMIT vp<%12> = VF * UF +(nuw)  vp<%2>
      EMIT branch-on-count  vp<%12> vp<%1>
    No successors
  }

In the good case the VPlan uses scalar-steps recipe instead:

  VPlan 'Initial VPlan for VF={1},UF>=1' {
  Live-in vp<%1> = vector-trip-count
  
  vector.ph:
  Successor(s): vector loop
  
  <x1> vector loop: {
    vector.body:
      EMIT vp<%2> = CANONICAL-INDUCTION
      FIRST-ORDER-RECURRENCE-PHI ir<%prev.011> = phi ir<0>, vp<%5>
      WIDEN-REDUCTION-PHI ir<%count.010> = phi ir<0>, ir<%count.1>
      vp<%5>    = SCALAR-STEPS vp<%2>, ir<0>, ir<1>
      EMIT vp<%6> = first-order splice ir<%prev.011> vp<%5>
      CLONE ir<%arrayidx> = getelementptr ir<%p>, vp<%6>
      CLONE ir<%6> = load ir<%arrayidx>
      CLONE ir<%cmp1> = fcmp ir<%6>, ir<0.000000e+00>
      CLONE ir<%inc> = zext ir<%cmp1>
      CLONE ir<%count.1> = add ir<%count.010>, ir<%inc>
      EMIT vp<%12> = VF * UF +(nuw)  vp<%2>
      EMIT branch-on-count  vp<%12> vp<%1>
    No successors
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123720



More information about the llvm-commits mailing list