anchor.diff:      buffer.add(';\n');
     }
   
  +
     visitBoundsCheck(HBoundsCheck node) {
  -    HInstruction index = node.index;
  -    if (index.isConstant()) {
  -      HConstant constantInstruction = index;
  +    // TODO(ngeoffray): Separate the two checks of the bounds check, so,
  +    // e.g., the zero checks can be shared if possible.
  +    int TryGetIntConstantValue(HInstruction instruction, String errorMessage) {
  +      // Tests whether an [HInstruction] is a constant.
  +      // If it is a constant, and not an int constant, it fails.
  +      // If it's an int constant it returns the value.
  +      // Otherwise it's not a constant, and this function returns false.
  +      if (!instruction.isConstant()) return null;
  +      HConstant constantInstruction = instruction;
         Constant constant = constantInstruction.constant;
         if (!constant.isInt()) {
  -        compiler.internalError(
  -          'String or List index not a number',
  -          instruction: index);
  +        compiler.internalError(errorMessage, instruction: instruction);
         }
         IntConstant intConstant = constant;
  -      if (intConstant.value < 0) {
  -        generateThrowWithHelper('ioore', index);
  +      return intConstant.value;
  +    }
  +    int index = TryGetIntConstantValue(node.index,
  +                                       'String or List index not a number');
  +    if (index !== null) {
  +      if (index < 0) {
  +        addIndentation();
  +        generateThrowWithHelper('ioore', node.index);
  +        buffer.add(";\n");
           return;
         }
  +      int length = TryGetIntConstantValue(node.length,
  +                                          'String or List length not a number');
  +      if (length !== null) {
  +        if (index >= length) {
  +          addIndentation();
  +          generateThrowWithHelper('ioore', node.index);
  +          buffer.add(";\n");
  +        }
  +        return;
  +      }
  +      addIndentation();
         buffer.add('if (');
       } else {
  +      addIndentation();
         buffer.add('if (');
  -      use(index, JSPrecedence.RELATIONAL_PRECEDENCE);
  +      use(node.index, JSPrecedence.RELATIONAL_PRECEDENCE);
         buffer.add(' < 0 || ');
       }
  -    use(index, JSPrecedence.RELATIONAL_PRECEDENCE);
  +    use(node.index, JSPrecedence.RELATIONAL_PRECEDENCE);
       buffer.add(' >= ');
       use(node.length, JSPrecedence.SHIFT_PRECEDENCE);
       buffer.add(") ");
  -    generateThrowWithHelper('ioore', index);
  +    generateThrowWithHelper('ioore', node.index);
  +    buffer.add(";\n");
     }
   
     visitIntegerCheck(HIntegerCheck node) {
  +    HInstruction valueInstruction = node.value;
  +    if (valueInstruction.isConstant()) {
  +      HConstant valueConstantInstruction = valueInstruction;
  +      Constant value = valueConstantInstruction.constant;
  +      if (!value.isInt()) {
  +        generateThrowWithHelper('iae', valueInstruction);
  +      }
  +      return;
  +    }
       buffer.add('if (');
       use(node.value, JSPrecedence.EQUALITY_PRECEDENCE);
       buffer.add(' !== (');
  
positive.code:         } else {
            define(instruction);
          }
          // Control flow instructions know how to handle ';'.
          if (instruction is !HControlFlow && instruction is !HTypeGuard &&
              !isGeneratingExpression()) {
            buffer.add(';\n');
          }
        } else if (instruction is HIf) {
  
negative.code:         return;
        } else if (!isGenerateAtUseSite(instruction)) {
          if (instruction is !HIf && instruction is !HTypeGuard &&
              instruction is !HBoundsCheck && !isGeneratingExpression()) {
            addIndentation();
          }
          if (isGeneratingExpression()) {
  