<div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><table class="bz_comment_table" cellpadding="0" cellspacing="0" style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: small;"><tbody><tr><td style="vertical-align: top;"><div id="c0" class="bz_comment bz_first_comment" style="margin-bottom: 2em;"><div class="bz_first_comment_head" style="padding-top: 0.1em; padding-bottom: 0.1em; padding-left: 0.5em; background-color: rgb(224, 224, 224);"><span class="bz_comment_actions" style="margin: 0px 0.5em; float: right;">[<a href="http://llvm.org/bugs/show_bug.cgi?id=20122#add_comment" style="color: rgb(102, 51, 102);">reply</a>] <a href="http://llvm.org/bugs/show_bug.cgi?id=20122#" class="bz_collapse_comment" id="comment_link_0" title="Toggle comment display" style="color: rgb(102, 51, 102); text-decoration: none;">[-]</a></span><span class="bz_comment_number" style="margin: 0px 0.5em; float: right;"><a href="http://llvm.org/bugs/show_bug.cgi?id=20122#c0" style="color: rgb(102, 51, 102);">Description</a></span><span class="bz_comment_user" style="margin: 0px 0.5em;"><span class="vcard"><a class="email" href="mailto:wuhui1973@163.com" title="hui wu <wuhui1973@163.com>" style="color: rgb(102, 51, 102);"><span class="fn">hui wu</span></a> </span></span><span class="bz_comment_user_images"></span><span class="bz_comment_time" style="margin: 0px 0.5em;">2014-06-24 21:35:52 CDT</span></div><pre class="bz_comment_text" id="comment_text_0" style="font-size: medium; font-family: monospace; width: 50em;">In function CodeGenRegBank::computeRegUnitSets, below code fragment is used to calculate the transitive closure of set union of intersecting sets.

  // Iterate over all unit sets, including new ones added by this loop.
  unsigned NumRegUnitSubSets = RegUnitSets.size();
  for (unsigned Idx = 0, EndIdx = RegUnitSets.size(); Idx != EndIdx; ++Idx) {
    // In theory, this is combinatorial. In practice, it needs to be bounded
    // by a small number of sets for regpressure to be efficient.
    // If the assert is hit, we need to implement pruning.
    assert(Idx < (2*NumRegUnitSubSets) && "runaway unit set inference");

    // Compare new sets with all original classes.
    for (unsigned SearchIdx = (Idx >= NumRegUnitSubSets) ? 0 : Idx+1;
         SearchIdx != EndIdx; ++SearchIdx) {
      std::set<unsigned> Intersection;
      std::set_intersection(RegUnitSets[Idx].Units.begin(),
                            RegUnitSets[Idx].Units.end(),
                            RegUnitSets[SearchIdx].Units.begin(),
                            RegUnitSets[SearchIdx].Units.end(),
                            std::inserter(Intersection, Intersection.begin()));
      if (Intersection.empty())
        continue;

      // Speculatively grow the RegUnitSets to hold the new set.
      RegUnitSets.resize(RegUnitSets.size() + 1);
      RegUnitSets.back().Name =
        RegUnitSets[Idx].Name + "+" + RegUnitSets[SearchIdx].Name;

      std::set_union(RegUnitSets[Idx].Units.begin(),
                     RegUnitSets[Idx].Units.end(),
                     RegUnitSets[SearchIdx].Units.begin(),
                     RegUnitSets[SearchIdx].Units.end(),
                     std::inserter(RegUnitSets.back().Units,
                                   RegUnitSets.back().Units.begin()));

      // Find an existing RegUnitSet, or add the union to the unique sets.
      std::vector<RegUnitSet>::const_iterator SetI =
        findRegUnitSet(RegUnitSets, RegUnitSets.back());
      if (SetI != llvm::prior(RegUnitSets.end()))
        RegUnitSets.pop_back();
    }
  }

However, the use of EndIdx like that is not correct, it makes the for loop exiting too early without handling the new added sets. The correct way should be:

  // Iterate over all unit sets, including new ones added by this loop.
  unsigned NumRegUnitSubSets = RegUnitSets.size();
  for (unsigned Idx = 0; Idx != RegUnitSets.size(); ++Idx) {
    // In theory, this is combinatorial. In practice, it needs to be bounded
    // by a small number of sets for regpressure to be efficient.
    // If the assert is hit, we need to implement pruning.
    assert(Idx < (2*NumRegUnitSubSets) && "runaway unit set inference");

    // Compare new sets with all original classes.
    for (unsigned SearchIdx = (Idx >= NumRegUnitSubSets) ? 0 : Idx+1;
         SearchIdx != RegUnitSets.size(); ++SearchIdx) {
      std::set<unsigned> Intersection;
      std::set_intersection(RegUnitSets[Idx].Units.begin(),
                            RegUnitSets[Idx].Units.end(),
                            RegUnitSets[SearchIdx].Units.begin(),
                            RegUnitSets[SearchIdx].Units.end(),
                            std::inserter(Intersection, Intersection.begin()));
      if (Intersection.empty())
        continue;

      // Speculatively grow the RegUnitSets to hold the new set.
      RegUnitSets.resize(RegUnitSets.size() + 1);
      RegUnitSets.back().Name =
        RegUnitSets[Idx].Name + "+" + RegUnitSets[SearchIdx].Name;

      std::set_union(RegUnitSets[Idx].Units.begin(),
                     RegUnitSets[Idx].Units.end(),
                     RegUnitSets[SearchIdx].Units.begin(),
                     RegUnitSets[SearchIdx].Units.end(),
                     std::inserter(RegUnitSets.back().Units,
                                   RegUnitSets.back().Units.begin()));

      // Find an existing RegUnitSet, or add the union to the unique sets.
      std::vector<RegUnitSet>::const_iterator SetI =
        findRegUnitSet(RegUnitSets, RegUnitSets.back());
      if (SetI != llvm::prior(RegUnitSets.end()))
        RegUnitSets.pop_back();
    }
  }</pre></div><div id="c1" class="bz_comment" style="margin-bottom: 2em;"><div class="bz_comment_head" style="padding-top: 0.1em; padding-bottom: 0.1em; padding-left: 0.5em; background-color: rgb(224, 224, 224);"><span class="bz_comment_actions" style="margin: 0px 0.5em; float: right;">[<a href="http://llvm.org/bugs/show_bug.cgi?id=20122#add_comment" style="color: rgb(102, 51, 102);">reply</a>] <a href="http://llvm.org/bugs/show_bug.cgi?id=20122#" class="bz_collapse_comment" id="comment_link_1" title="Toggle comment display" style="color: rgb(102, 51, 102); text-decoration: none;">[-]</a></span><span class="bz_comment_number" style="margin: 0px 0.5em; float: right;"><a href="http://llvm.org/bugs/show_bug.cgi?id=20122#c1" style="color: rgb(102, 51, 102);">Comment 1</a></span><span class="bz_comment_user" style="margin: 0px 0.5em;"><span class="vcard"><a class="email" href="mailto:hfinkel@anl.gov" title="Hal Finkel <hfinkel@anl.gov>" style="color: rgb(102, 51, 102);"><span class="fn">Hal Finkel</span></a> </span></span><span class="bz_comment_user_images"></span><span class="bz_comment_time" style="margin: 0px 0.5em;">2014-06-25 05:02:27 CDT</span></div><pre class="bz_comment_text" id="comment_text_1" style="font-size: medium; font-family: monospace; width: 50em;">Thanks for filing this bug; do you know if this is still a problem in llvm trunk? If so, the best way to provide this fix is to send a patch to the llvm-commits mailing list. That is how we normally review proposed patches.

<a href="http://llvm.org/docs/DeveloperPolicy.html#making-and-submitting-a-patch" style="color: rgb(102, 51, 102);">http://llvm.org/docs/DeveloperPolicy.html#making-and-submitting-a-patch</a>

Also, if you know how to generate a test that triggers the incorrect behavior, that would be great!</pre></div></td></tr></tbody></table></div><br><br><span title="neteasefooter"><span id="netease_mail_footer"></span></span>