[llvm] [VPlan] Verify scalar types in VPlanVerifier. NFCI (PR #122679)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 13 20:29:15 PST 2025


================
@@ -60,7 +60,10 @@ Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPInstruction *R) {
   }
   case Instruction::ICmp:
   case VPInstruction::ActiveLaneMask:
-    return inferScalarType(R->getOperand(1));
+    assert(inferScalarType(R->getOperand(0)) ==
+               inferScalarType(R->getOperand(1)) &&
+           "different types inferred for different operands");
+    return IntegerType::get(Ctx, 1);
----------------
lukel97 wrote:

Yeah in about 34 of the test cases, it mainly triggers when checking the operands of an or VPInstruction. The below is from llvm/test/Transforms/LoopVectorize/single_early_exit.ll and triggers the asesrtion on `vp<%11>`:

```
Live-in vp<%1> = vector-trip-count
<x1> vector loop: {
  vector.body:
    EMIT vp<%3> = CANONICAL-INDUCTION ir<0>, vp<%index.next>
    vp<%4> = DERIVED-IV ir<3> + vp<%3> * ir<1>
    vp<%5> = SCALAR-STEPS vp<%4>, ir<1>
    CLONE ir<%arrayidx> = getelementptr inbounds ir<%p1>, vp<%5>
    vp<%6> = vector-pointer ir<%arrayidx>
    WIDEN ir<%ld1> = load vp<%6>
    CLONE ir<%arrayidx1> = getelementptr inbounds ir<%p2>, vp<%5>
    vp<%7> = vector-pointer ir<%arrayidx1>
    WIDEN ir<%ld2> = load vp<%7>
    WIDEN ir<%cmp3> = icmp eq ir<%ld1>, ir<%ld2>
    EMIT vp<%index.next> = add nuw vp<%3>, vp<%0>
    EMIT vp<%8> = not ir<%cmp3>
    EMIT vp<%9> = any-of vp<%8>
    EMIT vp<%10> = icmp eq vp<%index.next>, vp<%1>
    EMIT vp<%11> = or vp<%9>, vp<%10>
    EMIT branch-on-cond vp<%11>
  No successors
}
```

`EMIT vp<%10> = icmp` has an inferred scalar type of i64 from the vector-trip-count `vp<%1>`.
But `vp<%9>` gets i1 from the `WIDEN ir<%cmp3> = icmp`.

I think the EMIT icmp should also be i1, to bring it inline with VPWidenRecipe:

```c++
Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPWidenRecipe *R) {
  unsigned Opcode = R->getOpcode();
   ...

  switch (Opcode) {
  case Instruction::ICmp:
  case Instruction::FCmp:
    return IntegerType::get(Ctx, 1);
```

https://github.com/llvm/llvm-project/pull/122679


More information about the llvm-commits mailing list