@Test
public void exprSimplificationAndLoopSplitInteraction() throws Exception {

  String program = "void main() {"
      + "  if(_GLF_DEAD(_GLF_FALSE(false, false))) {"
      // The expressions in here can now be reduced to constants, and there was an issue where
      // this was affecting loop merging.
      + "        for(\n"
      + "            int _GLF_SPLIT_LOOP_COUNTER_1n = 0;\n"
      + "            _GLF_SPLIT_LOOP_COUNTER_1n < 3;\n"
      + "            _GLF_SPLIT_LOOP_COUNTER_1n ++\n"
      + "        )\n"
      + "            {\n"
      + "            }\n"
      + "        for(\n"
      + "            int _GLF_SPLIT_LOOP_COUNTER_1n = 3;\n"
      + "            _GLF_SPLIT_LOOP_COUNTER_1n < 3;\n"
      + "            _GLF_SPLIT_LOOP_COUNTER_1n ++\n"
      + "        )\n"
      + "            {\n"
      + "            }\n"
      + "  }\n"
      + "}\n";
  TranslationUnit tu = ParseHelper.parse(program);
  List<Integer> indicesOfExprToConstOps = new ArrayList<>();
  {
    List<IReductionOpportunity> ops = ReductionOpportunities
        .getReductionOpportunities(MakeShaderJobFromFragmentShader.make(tu),
          new ReducerContext(false, ShadingLanguageVersion.ESSL_100,
              new RandomWrapper(0), new IdGenerator()), fileOps);
    for (int i = 0; i < ops.size(); i++) {
      if (ops.get(i) instanceof SimplifyExprReductionOpportunity) {
        indicesOfExprToConstOps.add(i);
      }
    }
  }
  // Check that applying an ExprToConstant followed by all loop merges does not fail.
  for (Integer index : indicesOfExprToConstOps) {
    final TranslationUnit tuClone = tu.clone();
    {
      final List<IReductionOpportunity> ops = ReductionOpportunities.getReductionOpportunities(
            MakeShaderJobFromFragmentShader.make(tuClone),
            new ReducerContext(false,
          ShadingLanguageVersion.ESSL_100, new RandomWrapper(0), new IdGenerator()), fileOps);
      ((SimplifyExprReductionOpportunity) ops.get(index)).applyReduction();
    }
    for (IReductionOpportunity op : ReductionOpportunities
            .getReductionOpportunities(MakeShaderJobFromFragmentShader.make(tuClone),
          new ReducerContext(false,
        ShadingLanguageVersion.ESSL_100, new RandomWrapper(0), new IdGenerator()), fileOps)) {
      if (op instanceof LoopMergeReductionOpportunity) {
        op.applyReduction();
      }
    }
  }
}