<commit_before>#!/usr/bin/env python

"""A shuffle vector fuzz tester.

This is a python program to fuzz test the LLVM shufflevector instruction. It
generates a function with a random sequnece of shufflevectors, maintaining the
element mapping accumulated across the function. It then generates a main
function which calls it with a different value in each element and checks that
the result matches the expected mapping.

Take the output IR printed to stdout, compile it to an executable using whatever
set of transforms you want to test, and run the program. If it crashes, it found
a bug.
"""

import argparse
import itertools
import random
import sys
import uuid

def main():
  parser = argparse.ArgumentParser(description=__doc__)
  parser.add_argument('-v', '--verbose', action='store_true',
                      help='Show verbose output')
  parser.add_argument('--seed', default=str(uuid.uuid4()),
                      help='A string used to seed the RNG')
  parser.add_argument('--max-shuffle-height', type=int, default=16,
                      help='Specify a fixed height of shuffle tree to test')
  parser.add_argument('--no-blends', dest='blends', action='store_false',
                      help='Include blends of two input vectors')
  parser.add_argument('--fixed-bit-width', type=int, choices=[128, 256],
                      help='Specify a fixed bit width of vector to test')
  parser.add_argument('--triple',
                      help='Specify a triple string to include in the IR')
  args = parser.parse_args()

  random.seed(args.seed)

  if args.fixed_bit_width is not None:
    if args.fixed_bit_width == 128:
      (width, element_type) = random.choice(
          [(2, 'i64'), (4, 'i32'), (8, 'i16'), (16, 'i8'),
           (2, 'f64'), (4, 'f32')])
    elif args.fixed_bit_width == 256:
      (width, element_type) = random.choice([
          (4, 'i64'), (8, 'i32'), (16, 'i16'), (32, 'i8'),
          (4, 'f64'), (8, 'f32')])
    else:
      sys.exit(1) # Checked above by argument parsing.
  else:
    width = random.choice([2, 4, 8, 16, 32, 64])
    element_type = random.choice(['i8', 'i16', 'i32', 'i64', 'f32', 'f64'])

  element_modulus = {
      'i8': 1 << 8, 'i16': 1 << 16, 'i32': 1 << 32, 'i64': 1 << 64,
      'f32': 1 << 32, 'f64': 1 << 64}[element_type]

  shuffle_range = (2 * width) if args.blends else width

  # Because undef (-1) saturates and is indistinguishable when testing the<commit_msg>[shuffle] Teach the shufflevector fuzzer to support fixed element types.<commit_after>#!/usr/bin/env python

"""A shuffle vector fuzz tester.

This is a python program to fuzz test the LLVM shufflevector instruction. It
generates a function with a random sequnece of shufflevectors, maintaining the
element mapping accumulated across the function. It then generates a main
function which calls it with a different value in each element and checks that
the result matches the expected mapping.

Take the output IR printed to stdout, compile it to an executable using whatever
set of transforms you want to test, and run the program. If it crashes, it found
a bug.
"""

import argparse
import itertools
import random
import sys
import uuid

def main():
  element_types=['i8', 'i16', 'i32', 'i64', 'f32', 'f64']
  parser = argparse.ArgumentParser(description=__doc__)
  parser.add_argument('-v', '--verbose', action='store_true',
                      help='Show verbose output')
  parser.add_argument('--seed', default=str(uuid.uuid4()),
                      help='A string used to seed the RNG')
  parser.add_argument('--max-shuffle-height', type=int, default=16,
                      help='Specify a fixed height of shuffle tree to test')
  parser.add_argument('--no-blends', dest='blends', action='store_false',
                      help='Include blends of two input vectors')
  parser.add_argument('--fixed-bit-width', type=int, choices=[128, 256],
                      help='Specify a fixed bit width of vector to test')
  parser.add_argument('--fixed-element-type', choices=element_types,
                      help='Specify a fixed element type to test')
  parser.add_argument('--triple',
                      help='Specify a triple string to include in the IR')
  args = parser.parse_args()

  random.seed(args.seed)

  if args.fixed_element_type is not None:
    element_types=[args.fixed_element_type]

  if args.fixed_bit_width is not None:
    if args.fixed_bit_width == 128:
      width_map={'i64': 2, 'i32': 4, 'i16': 8, 'i8': 16, 'f64': 2, 'f32': 4}
      (width, element_type) = random.choice(
          [(width_map[t], t) for t in element_types])
    elif args.fixed_bit_width == 256:
      width_map={'i64': 4, 'i32': 8, 'i16': 16, 'i8': 32, 'f64': 4, 'f32': 8}
      (width, element_type) = random.choice(
          [(width_map[t], t) for t in element_types])
    else:
      sys.exit(1) # Checked above by argument parsing.
  else:
    width = random.choice([2, 4, 8, 16, 32, 64])
    element_type = random.choice(element_types)

  element_modulus = {
      'i8': 1 << 8, 'i16': 1 << 16, 'i32': 1 << 32, 'i64': 1 << 64,
      'f32': 1 << 32, 'f64': 1 << 64}[element_type]

  shuffle_range = (2 * width) if args.blends else width

  # Because undef (-1) saturates and is indistinguishable when testing the
{'fraction_non_alphanumeric': 0.1296261150123363, 'fraction_numerical': 0.03909660277092428, 'mean_word_length': 3.1561514195583595, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7020138', 'n_tokens_mistral': 1798, 'n_tokens_neox': 1602, 'n_words': 574}