plctlab / llvm-project

PLCT实验室的 RISC-V V Spec 实现,基于llvm/llvm-project,rkruppe/rvv-llvm 和 https://repo.hca.bsc.es/gitlab/rferrer/llvm-epi-0.8
158 stars 42 forks source link

[VP][LV] Migrate vector predication pass and intrinsics from llvm-bpevl. #65

Closed AinsleySnow closed 8 months ago

AinsleySnow commented 8 months ago

This patch migrate two commit implementing the vector predication pass from LLVM bpEVL.

The two commits is based on the loop vectorizer one year ago, but now details of loop vectorizer changed and some code in these commits must be changed accordingly.

Modification to VPIntrinsics.def introduced by bpevl is dropped, because #66199 already added the same defination.

D158779 simplified the logic of addCanonicalIVRecipes, and move part of its code to addVPLaneMaskPhiAndUpdateExitBranch. Since the first commit has something to do with the moved logic, I modified the prototype of addActiveLaneMask, addVPLaneMaskPhiAndUpdateExitBranch and let addCanonicalIVRecipes return NextEVL to make sure NextEVL is insert to the exiting block as in the origin commit.

D147964 deleted the loop for setting TripCount in the start of VPlan::prepareToExecute (VPlan.cpp, line 616-621), therefore code in the first commit accessing trip count through State.get (example) will get undesired result and eventually crash the program. So I modified the code to get TripCount stored in the recipes directly (VPlanRecipes.cpp, line 1829 and VPlanRecipes.cpp, line 447).

#74761 remove the CanonicalIVIncrement VPInstruction (link) and use add instruction instead but part of the logic of the first commit relies on it. So I modified the processing logic of binary operator (VPlan.cpp, line 284-295) to add them.

Finally I updated vp_intrinsics.ll. The changes are likely introduced by other changes of LV but not by mistakes in migration.

AinsleySnow commented 8 months ago

The following tests crashed in my environment:

  Clang :: Driver/baremetal.cpp
  Clang :: Driver/csky-toolchain.c
  Clang :: Driver/freebsd-include-paths.c
  Clang :: Driver/haiku.c
  Clang :: Driver/hexagon-toolchain-linux.c
  Clang :: Driver/riscv32-toolchain-extra.c
  Clang :: Driver/riscv64-toolchain-extra.c
  Clang :: Driver/solaris-ld.c
  Clang :: Modules/embed-files-compressed.cpp
  Clang :: OpenMP/declare_variant_device_isa_codegen_1.c
  LLVM :: CodeGen/Generic/live-debug-label.ll

But they still crash even without this patch. Maybe we need a ci to run the tests, just like what we do in ruyisdk.