xref: /minix3/external/bsd/llvm/dist/llvm/test/CodeGen/X86/saddo-redundant-add.ll (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc; RUN: llc < %s -mtriple=x86_64-apple-darwin | FileCheck %s
2*0a6a1f1dSLionel Sambuc
3*0a6a1f1dSLionel Sambucdefine void @redundant_add(i64 %n) {
4*0a6a1f1dSLionel Sambuc; Check that we don't create two additions for the sadd.with.overflow.
5*0a6a1f1dSLionel Sambuc; CHECK-LABEL: redundant_add
6*0a6a1f1dSLionel Sambuc; CHECK-NOT:  leaq
7*0a6a1f1dSLionel Sambuc; CHECK-NOT:  addq
8*0a6a1f1dSLionel Sambuc; CHECK:      incq
9*0a6a1f1dSLionel Sambuc; CHECK-NEXT: jno
10*0a6a1f1dSLionel Sambucentry:
11*0a6a1f1dSLionel Sambuc  br label %exit_check
12*0a6a1f1dSLionel Sambuc
13*0a6a1f1dSLionel Sambucexit_check:
14*0a6a1f1dSLionel Sambuc  %i = phi i64 [ 0, %entry ], [ %i.next, %loop ]
15*0a6a1f1dSLionel Sambuc  %c = icmp slt i64 %i, %n
16*0a6a1f1dSLionel Sambuc  br i1 %c, label %loop, label %exit
17*0a6a1f1dSLionel Sambuc
18*0a6a1f1dSLionel Sambucloop:
19*0a6a1f1dSLionel Sambuc  %i.o = tail call { i64, i1 } @llvm.sadd.with.overflow.i64(i64 %i, i64 1)
20*0a6a1f1dSLionel Sambuc  %i.next = extractvalue { i64, i1 } %i.o, 0
21*0a6a1f1dSLionel Sambuc  %o = extractvalue { i64, i1 } %i.o, 1
22*0a6a1f1dSLionel Sambuc  br i1 %o, label %overflow, label %exit_check
23*0a6a1f1dSLionel Sambuc
24*0a6a1f1dSLionel Sambucexit:
25*0a6a1f1dSLionel Sambuc  ret void
26*0a6a1f1dSLionel Sambuc
27*0a6a1f1dSLionel Sambucoverflow:
28*0a6a1f1dSLionel Sambuc  tail call void @llvm.trap()
29*0a6a1f1dSLionel Sambuc  unreachable
30*0a6a1f1dSLionel Sambuc}
31*0a6a1f1dSLionel Sambuc
32*0a6a1f1dSLionel Sambucdeclare { i64, i1 } @llvm.sadd.with.overflow.i64(i64, i64)
33*0a6a1f1dSLionel Sambucdeclare void @llvm.trap()
34*0a6a1f1dSLionel Sambuc
35