Rafael Espindola | 04c2258 | 2014-06-04 15:39:14 +0000 | [diff] [blame^] | 1 | ; RUN: opt < %s -instcombine -S | FileCheck %s |
| 2 | |
| 3 | target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" |
| 4 | |
| 5 | ; CHECK-LABEL: @oppositesign |
| 6 | ; CHECK: add nsw i16 %a, %b |
| 7 | define i16 @oppositesign(i16 %x, i16 %y) { |
| 8 | ; %a is negative, %b is positive |
| 9 | %a = or i16 %x, 32768 |
| 10 | %b = and i16 %y, 32767 |
| 11 | %c = add i16 %a, %b |
| 12 | ret i16 %c |
| 13 | } |
| 14 | |
| 15 | ; CHECK-LABEL: @ripple_nsw1 |
| 16 | ; CHECK: add nsw i16 %a, %b |
| 17 | define i16 @ripple_nsw1(i16 %x, i16 %y) { |
| 18 | ; %a has at most one bit set |
| 19 | %a = and i16 %y, 1 |
| 20 | |
| 21 | ; %b has a 0 bit other than the sign bit |
| 22 | %b = and i16 %x, 49151 |
| 23 | |
| 24 | %c = add i16 %a, %b |
| 25 | ret i16 %c |
| 26 | } |
| 27 | |
| 28 | ; Like the previous test, but flip %a and %b |
| 29 | ; CHECK-LABEL: @ripple_nsw2 |
| 30 | ; CHECK: add nsw i16 %b, %a |
| 31 | define i16 @ripple_nsw2(i16 %x, i16 %y) { |
| 32 | %a = and i16 %y, 1 |
| 33 | %b = and i16 %x, 49151 |
| 34 | %c = add i16 %b, %a |
| 35 | ret i16 %c |
| 36 | } |
| 37 | |
| 38 | ; CHECK-LABEL: @ripple_no_nsw1 |
| 39 | ; CHECK: add i32 %a, %x |
| 40 | define i32 @ripple_no_nsw1(i32 %x, i32 %y) { |
| 41 | ; We know nothing about %x |
| 42 | %a = and i32 %y, 1 |
| 43 | %b = add i32 %a, %x |
| 44 | ret i32 %b |
| 45 | } |
| 46 | |
| 47 | ; CHECK-LABEL: @ripple_no_nsw2 |
| 48 | ; CHECK: add i16 %a, %b |
| 49 | define i16 @ripple_no_nsw2(i16 %x, i16 %y) { |
| 50 | ; %a has at most one bit set |
| 51 | %a = and i16 %y, 1 |
| 52 | |
| 53 | ; %b has a 0 bit, but it is the sign bit |
| 54 | %b = and i16 %x, 32767 |
| 55 | |
| 56 | %c = add i16 %a, %b |
| 57 | ret i16 %c |
| 58 | } |