From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 553 invoked by alias); 26 Aug 2008 11:35:27 -0000 Received: (qmail 32541 invoked by uid 48); 26 Aug 2008 11:34:06 -0000 Date: Tue, 26 Aug 2008 11:35:00 -0000 Subject: [Bug tree-optimization/37239] New: peeling last iteration of a <= loop X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "bonzini at gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-08/txt/msg01965.txt.bz2 If the condition of the loop is tested within the loop with == or !=, it may be beneficial to peel off the final iteration of the loop by changing the condition to <. This happens in the attached benchmark's heapsort function where while ((maxIdx += maxIdx) <= last) { if (maxIdx != last && numbers[maxIdx] < numbers[maxIdx + 1]) maxIdx++; if (tmp >= numbers[maxIdx]) break; numbers[top] = numbers[maxIdx]; top = maxIdx; } can become while ((maxIdx += maxIdx) <= last) { if (numbers[maxIdx] < numbers[maxIdx + 1]) maxIdx++; if (tmp >= numbers[maxIdx]) break; numbers[top] = numbers[maxIdx]; top = maxIdx; } if (maxIdx == last && tmp < numbers[maxIdx]) { numbers[top] = numbers[maxIdx]; top = maxIdx; } enabling in turn if-conversion of the first branch. Performance of the benchmark is (-O3) basic 2.990 peeling only 2.730 if-conversion only 2.290 peel+if-convert 2.010 (faster than quicksort!!) ICC does this optimization. -- Summary: peeling last iteration of a <= loop Product: gcc Version: 4.3.2 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: bonzini at gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37239