[PATCH] D24097: Add testcases for PR30188

Sebastian Pop via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 31 12:09:15 PDT 2016


sebpop created this revision.
sebpop added reviewers: jmolloy, danielcdh, davidxl, mkuper, dberlin.
sebpop added subscribers: llvm-commits, cfe-commits.

Add testcases to clang test/ to make sure that the combined middle-end
optimizations do not regress on optimizing the number of loads in the loops.


https://reviews.llvm.org/D24097

Files:
  clang/test/CodeGen/pr30188.c
  clang/test/CodeGenCXX/pr30188.cpp

Index: clang/test/CodeGenCXX/pr30188.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeGenCXX/pr30188.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -O2 -emit-llvm -o - %s | FileCheck %s
+
+// Check that optimizers are able to optimize the number of loads in the loop.
+// CHECK: load
+// CHECK-NOT: load
+
+int test(float exp, float *array) {
+  int hi = 255;
+  int lo = 0;
+  int offset = 0;
+
+  while(hi > lo) {
+    unsigned delta = (hi - lo) / 2u;
+    delta = 1u > delta ? 1u : delta;
+    offset = lo + delta;
+
+    if (array[offset] > exp)
+      hi = hi - delta;
+    else
+      lo = lo + delta;
+  }
+
+  return offset;
+}
Index: clang/test/CodeGen/pr30188.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/pr30188.c
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -O2 -emit-llvm -o - %s | FileCheck %s
+
+// Check that optimizers are able to optimize the number of loads in the loop.
+// CHECK: load
+// CHECK: load
+// CHECK: load
+// CHECK-NOT: load
+
+struct b {
+  int x_;
+};
+
+struct a {
+  int l_;
+  struct b *data_;
+};
+
+int BinarySearch(struct a *input, struct b t) {
+  if (input->l_ > 0) {
+    int low = 0;
+    int high = input->l_;
+    while (high != low + 1) {
+      int mid = (high + low) / 2;
+      if (input->data_[mid].x_ > t.x_)
+        high = mid;
+      else
+        low = mid;
+    }
+    return low;
+  }
+  return -1;
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24097.69890.patch
Type: text/x-patch
Size: 1465 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160831/87cced5f/attachment.bin>


More information about the cfe-commits mailing list