diff options
| author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2015-02-24 00:08:41 +0000 |
|---|---|---|
| committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2015-02-24 00:08:41 +0000 |
| commit | 82ea3d45b56f85368b0cbcba3b082a64a1caa46e (patch) | |
| tree | 2df1f0022df7753302b8675874a0468f312b76e3 /llvm/test/Transforms/InstCombine/max-of-nots.ll | |
| parent | 736888c84b51c7cf1f8eccea6738ad54503c2d0a (diff) | |
| download | bcm5719-llvm-82ea3d45b56f85368b0cbcba3b082a64a1caa46e.tar.gz bcm5719-llvm-82ea3d45b56f85368b0cbcba3b082a64a1caa46e.zip | |
New instcombine rule: max(~a,~b) -> ~min(a, b)
This case is interesting because ScalarEvolutionExpander lowers min(a,
b) as ~max(~a,~b). I think the profitability heuristics can be made
more clever/aggressive, but this is a start.
Differential Revision: http://reviews.llvm.org/D7821
llvm-svn: 230285
Diffstat (limited to 'llvm/test/Transforms/InstCombine/max-of-nots.ll')
| -rw-r--r-- | llvm/test/Transforms/InstCombine/max-of-nots.ll | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstCombine/max-of-nots.ll b/llvm/test/Transforms/InstCombine/max-of-nots.ll new file mode 100644 index 00000000000..41e3038cbe2 --- /dev/null +++ b/llvm/test/Transforms/InstCombine/max-of-nots.ll @@ -0,0 +1,68 @@ +; RUN: opt -S -instcombine < %s | FileCheck %s + +define i32 @compute_min_2(i32 %x, i32 %y) { +; CHECK-LABEL: compute_min_2 + entry: + %not_x = sub i32 -1, %x + %not_y = sub i32 -1, %y + %cmp = icmp sgt i32 %not_x, %not_y + %not_min = select i1 %cmp, i32 %not_x, i32 %not_y + %min = sub i32 -1, %not_min + ret i32 %min + +; CHECK: %0 = icmp slt i32 %x, %y +; CHECK-NEXT: %1 = select i1 %0, i32 %x, i32 %y +; CHECK-NEXT: ret i32 %1 +} + +define i32 @compute_min_3(i32 %x, i32 %y, i32 %z) { +; CHECK-LABEL: compute_min_3 + entry: + %not_x = sub i32 -1, %x + %not_y = sub i32 -1, %y + %not_z = sub i32 -1, %z + %cmp_1 = icmp sgt i32 %not_x, %not_y + %not_min_1 = select i1 %cmp_1, i32 %not_x, i32 %not_y + %cmp_2 = icmp sgt i32 %not_min_1, %not_z + %not_min_2 = select i1 %cmp_2, i32 %not_min_1, i32 %not_z + %min = sub i32 -1, %not_min_2 + ret i32 %min + +; CHECK: %0 = icmp slt i32 %x, %y +; CHECK-NEXT: %1 = select i1 %0, i32 %x, i32 %y +; CHECK-NEXT: %2 = icmp slt i32 %1, %z +; CHECK-NEXT: %3 = select i1 %2, i32 %1, i32 %z +; CHECK-NEXT: ret i32 %3 +} + +define i32 @compute_min_arithmetic(i32 %x, i32 %y) { +; CHECK-LABEL: compute_min_arithmetic + entry: + %not_value = sub i32 3, %x + %not_y = sub i32 -1, %y + %cmp = icmp sgt i32 %not_value, %not_y + %not_min = select i1 %cmp, i32 %not_value, i32 %not_y + ret i32 %not_min + +; CHECK: %0 = add i32 %x, -4 +; CHECK-NEXT: %1 = icmp slt i32 %0, %y +; CHECK-NEXT: %2 = select i1 %1, i32 %0, i32 %y +; CHECK-NEXT: %3 = xor i32 %2, -1 +; CHECK-NEXT: ret i32 %3 +} + +declare void @fake_use(i32) + +define i32 @compute_min_pessimization(i32 %x, i32 %y) { +; CHECK-LABEL: compute_min_pessimization + entry: + %not_value = sub i32 3, %x + call void @fake_use(i32 %not_value) + %not_y = sub i32 -1, %y + %cmp = icmp sgt i32 %not_value, %not_y +; CHECK: %not_value = sub i32 3, %x +; CHECK: %cmp = icmp sgt i32 %not_value, %not_y + %not_min = select i1 %cmp, i32 %not_value, i32 %not_y + %min = sub i32 -1, %not_min + ret i32 %min +} |

