| ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --filter "LV: Found an estimated cost of [0-9]+(.[0-9]+)? for VF 1 For instruction:\s*%v0 = load" --filter "Cost of [0-9]+(.[0-9]+)? for VF [0-9]+: (INTERLEAVE-GROUP with factor [0-9]+,|EXPRESSION|REPLICATE|WIDEN)" --filter "^ ir<.* = load from index" --filter "LV: Selecting VF:" --filter "Estimated cost per lane" | |
| ; REQUIRES: asserts | |
| ; RUN: opt -mtriple=wasm32 -mattr=+simd128 -passes=loop-vectorize %s --debug-only=loop-vectorize --disable-output < %s 2>&1 | FileCheck %s | |
| ; RUN: opt -mtriple=wasm32 -mattr=+simd128 -passes=loop-vectorize %s --vectorizer-maximize-bandwidth --debug-only=loop-vectorize --disable-output < %s 2>&1 | FileCheck %s --check-prefix=MAX | |
| define hidden void @quantize_3d(ptr nofree noundef readonly captures(none) %input, | |
| ; CHECK-LABEL: 'quantize_3d' | |
| ; CHECK: Cost of 2 for VF 2: WIDEN ir<%value> = load vp<[[VP9:%[0-9]+]]>, align 4 (!alias.scope !3) | |
| ; CHECK: Cost of 2 for VF 2: WIDEN ir<%scaled> = fmul fast ir<%value>, ir<%scale> | |
| ; CHECK: Cost of 24 for VF 2: WIDEN-INTRINSIC ir<%rounded> = call fast llvm.round(ir<%scaled>) | |
| ; CHECK: Cost of 1 for VF 2: WIDEN-CAST ir<%converted> = fptosi ir<%rounded> to i32 | |
| ; CHECK: Cost of 1 for VF 2: WIDEN-INTRINSIC ir<%max> = call llvm.smax(ir<%converted>, ir<-127>) | |
| ; CHECK: Cost of 1 for VF 2: WIDEN-INTRINSIC ir<%min> = call llvm.smin(ir<%max>, ir<127>) | |
| ; CHECK: Cost of 4 for VF 2: WIDEN-CAST ir<%truncated> = trunc nsw ir<%min> to i8 | |
| ; CHECK: Cost of 2 for VF 2: WIDEN store vp<[[VP10:%[0-9]+]]>, ir<%truncated>, align 1 (!alias.scope !4, !noalias !3) | |
| ; CHECK: Cost for VF 2: 41 (Estimated cost per lane: 20.5) | |
| ; CHECK: Cost of 2 for VF 4: WIDEN ir<%value> = load vp<[[VP9]]>, align 4 (!alias.scope !3) | |
| ; CHECK: Cost of 2 for VF 4: WIDEN ir<%scaled> = fmul fast ir<%value>, ir<%scale> | |
| ; CHECK: Cost of 48 for VF 4: WIDEN-INTRINSIC ir<%rounded> = call fast llvm.round(ir<%scaled>) | |
| ; CHECK: Cost of 1 for VF 4: WIDEN-CAST ir<%converted> = fptosi ir<%rounded> to i32 | |
| ; CHECK: Cost of 1 for VF 4: WIDEN-INTRINSIC ir<%max> = call llvm.smax(ir<%converted>, ir<-127>) | |
| ; CHECK: Cost of 1 for VF 4: WIDEN-INTRINSIC ir<%min> = call llvm.smin(ir<%max>, ir<127>) | |
| ; CHECK: Cost of 3 for VF 4: WIDEN-CAST ir<%truncated> = trunc nsw ir<%min> to i8 | |
| ; CHECK: Cost of 2 for VF 4: WIDEN store vp<[[VP10]]>, ir<%truncated>, align 1 (!alias.scope !4, !noalias !3) | |
| ; CHECK: Cost for VF 4: 64 (Estimated cost per lane: 16) | |
| ; CHECK: LV: Selecting VF: 4. | |
| ; | |
| ; MAX-LABEL: 'quantize_3d' | |
| ; MAX: Cost of 2 for VF 2: WIDEN ir<%value> = load vp<[[VP9:%[0-9]+]]>, align 4 (!alias.scope !3) | |
| ; MAX: Cost of 2 for VF 2: WIDEN ir<%scaled> = fmul fast ir<%value>, ir<%scale> | |
| ; MAX: Cost of 24 for VF 2: WIDEN-INTRINSIC ir<%rounded> = call fast llvm.round(ir<%scaled>) | |
| ; MAX: Cost of 1 for VF 2: WIDEN-CAST ir<%converted> = fptosi ir<%rounded> to i32 | |
| ; MAX: Cost of 1 for VF 2: WIDEN-INTRINSIC ir<%max> = call llvm.smax(ir<%converted>, ir<-127>) | |
| ; MAX: Cost of 1 for VF 2: WIDEN-INTRINSIC ir<%min> = call llvm.smin(ir<%max>, ir<127>) | |
| ; MAX: Cost of 4 for VF 2: WIDEN-CAST ir<%truncated> = trunc nsw ir<%min> to i8 | |
| ; MAX: Cost of 2 for VF 2: WIDEN store vp<[[VP10:%[0-9]+]]>, ir<%truncated>, align 1 (!alias.scope !4, !noalias !3) | |
| ; MAX: Cost for VF 2: 41 (Estimated cost per lane: 20.5) | |
| ; MAX: Cost of 2 for VF 4: WIDEN ir<%value> = load vp<[[VP9]]>, align 4 (!alias.scope !3) | |
| ; MAX: Cost of 2 for VF 4: WIDEN ir<%scaled> = fmul fast ir<%value>, ir<%scale> | |
| ; MAX: Cost of 48 for VF 4: WIDEN-INTRINSIC ir<%rounded> = call fast llvm.round(ir<%scaled>) | |
| ; MAX: Cost of 1 for VF 4: WIDEN-CAST ir<%converted> = fptosi ir<%rounded> to i32 | |
| ; MAX: Cost of 1 for VF 4: WIDEN-INTRINSIC ir<%max> = call llvm.smax(ir<%converted>, ir<-127>) | |
| ; MAX: Cost of 1 for VF 4: WIDEN-INTRINSIC ir<%min> = call llvm.smin(ir<%max>, ir<127>) | |
| ; MAX: Cost of 3 for VF 4: WIDEN-CAST ir<%truncated> = trunc nsw ir<%min> to i8 | |
| ; MAX: Cost of 2 for VF 4: WIDEN store vp<[[VP10]]>, ir<%truncated>, align 1 (!alias.scope !4, !noalias !3) | |
| ; MAX: Cost for VF 4: 64 (Estimated cost per lane: 16) | |
| ; MAX: Cost of 2 for VF 8: WIDEN ir<%value> = load vp<[[VP9]]>, align 4 (!alias.scope !3) | |
| ; MAX: Cost of 4 for VF 8: WIDEN ir<%scaled> = fmul fast ir<%value>, ir<%scale> | |
| ; MAX: Cost of 96 for VF 8: WIDEN-INTRINSIC ir<%rounded> = call fast llvm.round(ir<%scaled>) | |
| ; MAX: Cost of 2 for VF 8: WIDEN-CAST ir<%converted> = fptosi ir<%rounded> to i32 | |
| ; MAX: Cost of 4 for VF 8: WIDEN-INTRINSIC ir<%max> = call llvm.smax(ir<%converted>, ir<-127>) | |
| ; MAX: Cost of 4 for VF 8: WIDEN-INTRINSIC ir<%min> = call llvm.smin(ir<%max>, ir<127>) | |
| ; MAX: Cost of 4 for VF 8: WIDEN-CAST ir<%truncated> = trunc nsw ir<%min> to i8 | |
| ; MAX: Cost of 2 for VF 8: WIDEN store vp<[[VP10]]>, ir<%truncated>, align 1 (!alias.scope !4, !noalias !3) | |
| ; MAX: Cost for VF 8: 122 (Estimated cost per lane: 15.3) | |
| ; MAX: Cost of 4 for VF 16: WIDEN ir<%value> = load vp<[[VP9]]>, align 4 (!alias.scope !3) | |
| ; MAX: Cost of 8 for VF 16: WIDEN ir<%scaled> = fmul fast ir<%value>, ir<%scale> | |
| ; MAX: Cost of 192 for VF 16: WIDEN-INTRINSIC ir<%rounded> = call fast llvm.round(ir<%scaled>) | |
| ; MAX: Cost of 4 for VF 16: WIDEN-CAST ir<%converted> = fptosi ir<%rounded> to i32 | |
| ; MAX: Cost of 8 for VF 16: WIDEN-INTRINSIC ir<%max> = call llvm.smax(ir<%converted>, ir<-127>) | |
| ; MAX: Cost of 8 for VF 16: WIDEN-INTRINSIC ir<%min> = call llvm.smin(ir<%max>, ir<127>) | |
| ; MAX: Cost of 7 for VF 16: WIDEN-CAST ir<%truncated> = trunc nsw ir<%min> to i8 | |
| ; MAX: Cost of 2 for VF 16: WIDEN store vp<[[VP10]]>, ir<%truncated>, align 1 (!alias.scope !4, !noalias !3) | |
| ; MAX: Cost for VF 16: 237 (Estimated cost per lane: 14.8) | |
| ; MAX: LV: Selecting VF: 16. | |
| ; | |
| ptr nofree noundef writeonly captures(none) %output, | |
| i32 noundef %count, | |
| ptr nofree noundef readonly captures(none) %scale.ptr) { | |
| entry: | |
| %scale = load float, ptr %scale.ptr, align 4 | |
| br label %loop | |
| loop: | |
| %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ] | |
| %output.ptr = phi ptr [ %output, %entry ], [ %output.next, %loop ] | |
| %input.ptr = phi ptr [ %input, %entry ], [ %input.next, %loop ] | |
| %input.next = getelementptr inbounds nuw i8, ptr %input.ptr, i32 4 | |
| %value = load float, ptr %input.ptr, align 4 | |
| %scaled = fmul fast float %value, %scale | |
| %rounded = tail call fast noundef nofpclass(nan inf) float @llvm.round.f32(float nofpclass(nan inf) %scaled) | |
| %converted = fptosi float %rounded to i32 | |
| %max = tail call i32 @llvm.smax.i32(i32 %converted, i32 -127) | |
| %min = tail call i32 @llvm.smin.i32(i32 %max, i32 127) | |
| %truncated = trunc nsw i32 %min to i8 | |
| %output.next = getelementptr inbounds nuw i8, ptr %output.ptr, i32 1 | |
| store i8 %truncated, ptr %output.ptr, align 1 | |
| %iv.next = add nuw nsw i32 %iv, 1 | |
| %exitcond = icmp eq i32 %iv.next, %count | |
| br i1 %exitcond, label %exit, label %loop | |
| exit: | |
| ret void | |
| } | |
| declare float @llvm.round.f32(float) | |
| declare i32 @llvm.smax.i32(i32, i32) | |
| declare i32 @llvm.smin.i32(i32, i32) |