Issue 243698
Summary [RISCV] assertion failure "cast() argument of incompatible type!" with loop vectorizer and RVV
Labels generated by fuzzer
Assignees
Reporter hazohelet
    Live Reproducer: https://godbolt.org/z/bbEanExMs

Compiling the following C code for `riscv64` with `clang -O2 -march=rv64gcv` crashes with assertion failure.

```c
__int128 g;
unsigned f(int x, int y, unsigned char z, int v) {
  unsigned r = 0;
  for (unsigned i = 0; i < 16 && (z || y); i++) {
 g = (y ? x : v) % 2;
    x = 0;
    if (!(v > i || y))
      break;
 r = 1;
  }
  return r;
}
```

clang command:

```sh
clang --target=riscv64-linux-gnu -march=rv64gcv -O2 -c repro.c
```

The compiler crashes with the following output:

```
clang: llvm/include/llvm/Support/Casting.h:572: decltype(auto) llvm::cast(From*) [with To = FixedVectorType; From = Type]: 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 and dumped files.
Stack dump:
0.	Program arguments: clang --target=riscv64-linux-gnu -march=rv64gcv -O2 -c repro.c
1.	<eof> parser at end of file
2.	Optimizer
3.	Running pass "function<eager-inv>(...)" on module "repro.c"
4.	Running pass "loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>" on function "f"
...
#11 llvm::RISCVTTIImpl::getVectorInstrCost(unsigned int, llvm::Type*, llvm::TargetTransformInfo::TargetCostKind, unsigned int, llvm::Value const*, llvm::Value const*, llvm::VectorInstrContext) const
#12 llvm::RISCVTTIImpl::getIndexedVectorInstrCostFromEnd(unsigned int, llvm::Type*, llvm::TargetTransformInfo::TargetCostKind, unsigned int) const
#13 llvm::TargetTransformInfo::getIndexedVectorInstrCostFromEnd(unsigned int, llvm::Type*, llvm::TargetTransformInfo::TargetCostKind, unsigned int) const
#14 llvm::VPRecipeBase::cost(llvm::ElementCount, llvm::VPCostContext&)
#15 llvm::VPBasicBlock::cost(llvm::ElementCount, llvm::VPCostContext&)
#16 llvm::VPlan::cost(llvm::ElementCount, llvm::VPCostContext&)
#17 llvm::LoopVectorizationPlanner::cost(llvm::VPlan&, llvm::ElementCount, llvm::VPRegisterUsage*, llvm::LoopVectorizationCostModel&) const
#18 llvm::LoopVectorizationPlanner::computeBestVF()
#19 llvm::LoopVectorizePass::processLoop(llvm::Loop*)
```

Notes:

* Compiles at -O1, -O3 and -Os, with `-fno-vectorize`, and with `-march=rv64gc`
* Compiles with `long` in place of `__int128`
* Clang 23.1.2 compiles it

clang version:

```text
clang version 24.0.0git (https://github.com/llvm/llvm-project 0c9e65d8f3d67c946058390eeec5d5a24125aaaf)
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to