1 ; RUN: llc < %s -mcpu=generic -march=x86 | FileCheck %s -check-prefix=X32
2 ; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux | FileCheck %s -check-prefix=X64
3 ; RUN: llc < %s -mcpu=generic -mtriple=x86_64-win32 | FileCheck %s -check-prefix=X64
5 ; The immediate can be encoded in a smaller way if the
6 ; instruction is a sub instead of an add.
8 define i32 @test1(i32 inreg %a) nounwind {
11 ; X32: subl $-128, %eax
14 define i64 @test2(i64 inreg %a) nounwind {
15 %b = add i64 %a, 2147483648
17 ; X32: addl $-2147483648, %eax
18 ; X64: subq $-2147483648,
20 define i64 @test3(i64 inreg %a) nounwind {
24 ; X32: addl $128, %eax
28 define i1 @test4(i32 %v1, i32 %v2, i32* %X) nounwind {
30 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %v1, i32 %v2)
31 %sum = extractvalue {i32, i1} %t, 0
32 %obit = extractvalue {i32, i1} %t, 1
33 br i1 %obit, label %overflow, label %normal
47 ; X64: addl %e[[A1:si|dx]], %e[[A0:di|cx]]
51 define i1 @test5(i32 %v1, i32 %v2, i32* %X) nounwind {
53 %t = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %v1, i32 %v2)
54 %sum = extractvalue {i32, i1} %t, 0
55 %obit = extractvalue {i32, i1} %t, 1
56 br i1 %obit, label %carry, label %normal
70 ; X64: addl %e[[A1]], %e[[A0]]
74 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32, i32)
75 declare {i32, i1} @llvm.uadd.with.overflow.i32(i32, i32)
78 define i64 @test6(i64 %A, i32 %B) nounwind {
79 %tmp12 = zext i32 %B to i64 ; <i64> [#uses=1]
80 %tmp3 = shl i64 %tmp12, 32 ; <i64> [#uses=1]
81 %tmp5 = add i64 %tmp3, %A ; <i64> [#uses=1]
85 ; X32: movl 12(%esp), %edx
86 ; X32-NEXT: addl 8(%esp), %edx
87 ; X32-NEXT: movl 4(%esp), %eax
91 ; X64: shlq $32, %r[[A1]]
92 ; X64: leaq (%r[[A1]],%r[[A0]]), %rax
96 define {i32, i1} @test7(i32 %v1, i32 %v2) nounwind {
97 %t = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %v1, i32 %v2)
102 ; X64: addl %e[[A1]], %e
107 define {i64, i1} @test8(i64 %left, i64 %right) nounwind {
109 %extleft = zext i64 %left to i65
110 %extright = zext i64 %right to i65
111 %sum = add i65 %extleft, %extright
112 %res.0 = trunc i65 %sum to i64
113 %overflow = and i65 %sum, -18446744073709551616
114 %res.1 = icmp ne i65 %overflow, 0
115 %final0 = insertvalue {i64, i1} undef, i64 %res.0, 0
116 %final1 = insertvalue {i64, i1} %final0, i1 %res.1, 1
117 ret {i64, i1} %final1
125 define i32 @test9(i32 %x, i32 %y) nounwind readnone {
126 %cmp = icmp eq i32 %x, 10
127 %sub = sext i1 %cmp to i32
128 %cond = add i32 %sub, %y
137 define i1 @test10(i32 %x) nounwind {
139 %t = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %x, i32 1)
140 %obit = extractvalue {i32, i1} %t, 1