def simd_loop_filter(loops, tuning):
    """ Filter out the SIMD candidate loops based on the tuning information.

    We select the legal simd loop with the highest score.
    If there is no such loop, we will set "loops" to all "1"s.
    AutoSA will not tile loops with the tiling factor as one for latency hiding or
    SIMD vectorization.
    If one such loop is found, we will set all loop bounds to 1 except the target loop.

    Parameters
    ----------
    loops: list
        upper bounds of all candidate SIMD loops
    tuning: dict
        tuning information for the SIMD stage
    """
    scores = tuning['simd']['scores']
    legal = tuning['simd']['legal']
    # Find the candidate loop with the highest score
    simd_loop_idx = -1
    max_score = -1
    for i in range(len(legal)):
        if legal[i] == 0:
            continue
        if scores[i] > max_score:
            max_score = scores[i]
            simd_loop_idx = i

    if simd_loop_idx < 0:
        filter_loops = [1 for i in range(len(loops))]
    else:
        filter_loops = [1 for i in range(len(loops))]
        filter_loops[simd_loop_idx] = loops[simd_loop_idx]

    return filter_loops