1 ; RUN: opt < %s -instcombine -S | FileCheck %s
3 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
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
10 %b = and i16 %y, 32767
15 define i16 @zero_sign_bit(i16 %a) {
16 ; CHECK-LABEL: @zero_sign_bit(
20 %1 = and i16 %a, 32767
25 define i16 @zero_sign_bit2(i16 %a, i16 %b) {
26 ; CHECK-LABEL: @zero_sign_bit2(
31 %1 = and i16 %a, 32767
32 %2 = and i16 %b, 32767
37 declare i16 @bounded(i16 %input);
38 declare i32 @__gxx_personality_v0(...);
39 !0 = metadata !{i16 0, i16 32768} ; [0, 32767]
40 !1 = metadata !{i16 0, i16 32769} ; [0, 32768]
42 define i16 @add_bounded_values(i16 %a, i16 %b) {
43 ; CHECK-LABEL: @add_bounded_values(
45 %c = call i16 @bounded(i16 %a), !range !0
46 %d = invoke i16 @bounded(i16 %b) to label %cont unwind label %lpad, !range !0
48 ; %c and %d are in [0, 32767]. Therefore, %c + %d doesn't unsigned overflow.
50 ; CHECK: add nuw i16 %c, %d
53 %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
54 filter [0 x i8*] zeroinitializer
58 define i16 @add_bounded_values_2(i16 %a, i16 %b) {
59 ; CHECK-LABEL: @add_bounded_values_2(
61 %c = call i16 @bounded(i16 %a), !range !1
62 %d = invoke i16 @bounded(i16 %b) to label %cont unwind label %lpad, !range !1
64 ; Similar to add_bounded_values, but %c and %d are in [0, 32768]. Therefore,
65 ; %c + %d may unsigned overflow and we cannot add NUW.
67 ; CHECK: add i16 %c, %d
70 %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
71 filter [0 x i8*] zeroinitializer
75 ; CHECK-LABEL: @ripple_nsw1
76 ; CHECK: add nsw i16 %a, %b
77 define i16 @ripple_nsw1(i16 %x, i16 %y) {
78 ; %a has at most one bit set
81 ; %b has a 0 bit other than the sign bit
82 %b = and i16 %x, 49151
88 ; Like the previous test, but flip %a and %b
89 ; CHECK-LABEL: @ripple_nsw2
90 ; CHECK: add nsw i16 %b, %a
91 define i16 @ripple_nsw2(i16 %x, i16 %y) {
93 %b = and i16 %x, 49151
98 ; CHECK-LABEL: @ripple_no_nsw1
99 ; CHECK: add i32 %a, %x
100 define i32 @ripple_no_nsw1(i32 %x, i32 %y) {
101 ; We know nothing about %x
107 ; CHECK-LABEL: @ripple_no_nsw2
108 ; CHECK: add nuw i16 %a, %b
109 define i16 @ripple_no_nsw2(i16 %x, i16 %y) {
110 ; %a has at most one bit set
113 ; %b has a 0 bit, but it is the sign bit
114 %b = and i16 %x, 32767