llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[SLP] Unguarded call to SmallVector::front() in TrySplitNode lambda

Open wjschmidt opened this issue 1 year ago • 2 comments

In the calculation of NewCost in TrySplitNode, there are two calls to VectorizableTree.front() that will assert if VectorizableTree is empty. The following small test case causes a crash as a result.

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.1 = type { [258 x [1 x i32]], [56 x i8], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [2 x [16 x [1 x i32]]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [10 x [16 x [1 x i32]]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [16 x [1 x i32]], [2 x [1 x i32]], [56 x i8], [2 x [1 x i32]], [56 x i8], [2 x [1 x i32]], [56 x i8] }

define <8 x float> @foo(i32 %0, i32 %1, i32 %2) #0 {
entry:
  %vecext.i615 = extractelement <4 x i32> zeroinitializer, i64 0
  %idx.ext = sext i32 %vecext.i615 to i64
  %__u.i613 = getelementptr i8, ptr getelementptr inbounds (%struct.1, ptr null, i64 -35, i32 37, i64 0, i64 0), i64 %idx.ext
  %idx.ext320 = sext i32 %0 to i64
  %__u.i611 = getelementptr i8, ptr getelementptr inbounds (%struct.1, ptr null, i64 -35, i32 37, i64 0, i64 0), i64 %idx.ext320
  %idx.ext326 = sext i32 %1 to i64
  %__u.i609 = getelementptr i8, ptr getelementptr inbounds (%struct.1, ptr null, i64 -35, i32 37, i64 0, i64 0), i64 %idx.ext326
  %idx.ext332 = sext i32 %2 to i64
  %__u.i607 = getelementptr i8, ptr getelementptr inbounds (%struct.1, ptr null, i64 -35, i32 37, i64 0, i64 0), i64 %idx.ext332
  %idx.ext338 = zext i32 %2 to i64
  %__u.i605 = getelementptr i8, ptr getelementptr inbounds (%struct.1, ptr null, i64 -35, i32 37, i64 0, i64 0), i64 %idx.ext338
  %idx.ext344 = zext i32 %1 to i64
  %__u.i603 = getelementptr i8, ptr getelementptr inbounds (%struct.1, ptr null, i64 -35, i32 37, i64 0, i64 0), i64 %idx.ext344
  %idx.ext350 = zext i32 0 to i64
  %__u.i601 = getelementptr i8, ptr getelementptr inbounds (%struct.1, ptr null, i64 -35, i32 37, i64 0, i64 0), i64 %idx.ext350
  %idx.ext356 = zext i32 %0 to i64
  %__u.i = getelementptr i8, ptr getelementptr inbounds (%struct.1, ptr null, i64 -35, i32 37, i64 0, i64 0), i64 %idx.ext356
  ret <8 x float> zeroinitializer
}

attributes #0 = { "target-cpu"="core-avx2" }

wjschmidt avatar Mar 17 '25 16:03 wjschmidt

Tagging @alexey-bataev for information.

wjschmidt avatar Mar 17 '25 16:03 wjschmidt

Thanks, @alexey-bataev !

wjschmidt avatar Mar 17 '25 18:03 wjschmidt