[PATCH] D24593: Standford/Bubble sort code restructure
Evgeny Stupachenko via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 14 16:07:13 PDT 2016
evstupac created this revision.
evstupac added reviewers: MatzeB, mehdi_amini, hfinkel.
evstupac added subscribers: llvm-commits, mzolotukhin.
1. Fix potential issue with MAX and MIN elements in array (that should be always one of array elements).
2. Based on https://reviews.llvm.org/D18158 it turned out that currently bubble sort is a flaky test.
The flakiness caused by unpredictable memory accesses to array and code:
if (a[i] > a[i + 1) { // load a[i], a[i+1];
// store to a[i], a[i+1];
}
Making stores unconditional will simplify memory accesses and potentially CFG.
This will open the test for compiler optimizations (like unroll, scalar replacement, if conversion...).
Generally the idea to convert the test from memory test to compiler test.
https://reviews.llvm.org/D24593
Files:
SingleSource/Benchmarks/Stanford/Bubblesort.c
SingleSource/Benchmarks/Stanford/Quicksort.c
SingleSource/Benchmarks/Stanford/Treesort.c
Index: SingleSource/Benchmarks/Stanford/Quicksort.c
===================================================================
--- SingleSource/Benchmarks/Stanford/Quicksort.c
+++ SingleSource/Benchmarks/Stanford/Quicksort.c
@@ -127,8 +127,10 @@
int i; /* temp */
long temp; /* made temp a long for 16 bit WR*/
Initrand();
- biggest = 0; littlest = 0;
- for ( i = 1; i <= sortelements; i++ ) {
+ temp = Rand();
+ sortlist[1] = (int)(temp - (temp / 100000L) * 100000L - 50000L);
+ biggest = sortlist[1]; littlest = sortlist[1];
+ for ( i = 2; i <= sortelements; i++ ) {
temp = Rand();
/* converted constants to long in next stmt, typecast back to int WR*/
sortlist[i] = (int)(temp - (temp/100000L)*100000L - 50000L);
Index: SingleSource/Benchmarks/Stanford/Treesort.c
===================================================================
--- SingleSource/Benchmarks/Stanford/Treesort.c
+++ SingleSource/Benchmarks/Stanford/Treesort.c
@@ -129,8 +129,10 @@
int i;
long temp; /* converted temp to long for 16 bit WR*/
Initrand();
- biggest = 0; littlest = 0;
- for ( i = 1; i <= sortelements; i++ ) {
+ temp = Rand();
+ sortlist[1] = (int)(temp - (temp / 100000L) * 100000L - 50000L);
+ biggest = sortlist[1]; littlest = sortlist[1];
+ for ( i = 2; i <= sortelements; i++ ) {
temp = Rand();
/* converted constants to long in next stmt, typecast back to int WR*/
sortlist[i] = (int)(temp - (temp/100000L)*100000L - 50000L);
Index: SingleSource/Benchmarks/Stanford/Bubblesort.c
===================================================================
--- SingleSource/Benchmarks/Stanford/Bubblesort.c
+++ SingleSource/Benchmarks/Stanford/Bubblesort.c
@@ -128,8 +128,10 @@
int i;
long temp; /* converted temp to long for 16 bit WR*/
Initrand();
- biggest = 0; littlest = 0;
- for ( i = 1; i <= srtelements; i++ ) {
+ temp = Rand();
+ sortlist[1] = (int)(temp - (temp / 100000L) * 100000L - 50000L);
+ biggest = sortlist[1]; littlest = sortlist[1];
+ for ( i = 2; i <= srtelements; i++ ) {
temp = Rand();
/* converted constants to long in next stmt, typecast back to int WR*/
sortlist[i] = (int)(temp - (temp/100000L)*100000L - 50000L);
@@ -147,12 +149,15 @@
i=1;
while ( i<top ) {
-
- if ( sortlist[i] > sortlist[i+1] ) {
- j = sortlist[i];
- sortlist[i] = sortlist[i+1];
- sortlist[i+1] = j;
+ int sli = sortlist[i];
+ int sli1 = sortlist[i + 1];
+ if ( sli > sli1 ) {
+ j = sli;
+ sli = sli1;
+ sli1 = j;
}
+ sortlist[i] = sli;
+ sortlist[i + 1] = sli1;
i=i+1;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24593.71458.patch
Type: text/x-patch
Size: 2577 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160914/3d8f0985/attachment.bin>
More information about the llvm-commits
mailing list