; The test is generated by Clang from the following source:
;
; void foo32(int a, int b, int *c) {
;   *c = a + b;
; }
;
; void foo64(long a, long b, long *c) {
;   *c = a + b;
; }
;
; With the following options:
; -emit-llvm -fno-discard-value-names -O2 -g0 -ftrapv -target spir

; RUN: llvm-as < %s -o %t.bc
; RUN: llvm-spirv -s %t.bc -o - | llvm-dis -o - | FileCheck %s

; CHECK: call { i32, i1 } @llvm_sadd_with_overflow_i32{{.*}} !nosanitize !2
; CHECK-NOT: call { i32, i1 } @llvm.sadd.with.overflow.i32

; CHECK: call { i64, i1 } @llvm_sadd_with_overflow_i64{{.*}} !nosanitize !2
; CHECK-NOT: call { i64, i1 } @llvm.sadd.with.overflow.i64

; CHECK-NOT: call { i16, i1 } @llvm_sadd_with_overflow_i16


target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir"

; Function Attrs: nounwind
define dso_local spir_func void @foo32(i32 %a, i32 %b, ptr nocapture %c) local_unnamed_addr #0 {
entry:
  %0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %a, i32 %b), !nosanitize !2
  %1 = extractvalue { i32, i1 } %0, 1, !nosanitize !2
  br i1 %1, label %trap, label %cont, !nosanitize !2

trap:                                             ; preds = %entry
  tail call void @llvm.trap() #3, !nosanitize !2
  unreachable, !nosanitize !2

cont:                                             ; preds = %entry
  %2 = extractvalue { i32, i1 } %0, 0, !nosanitize !2
  store i32 %2, ptr %c, align 4, !tbaa !3
  ret void
}

; Function Attrs: nounwind readnone speculatable willreturn
declare { i32, i1 } @llvm.sadd.with.overflow.i32(i32, i32) #1

; Function Attrs: cold noreturn nounwind
declare void @llvm.trap() #2

; Function Attrs: nounwind
define dso_local spir_func void @foo64(i64 %a, i64 %b, ptr nocapture %c) local_unnamed_addr #0 {
entry:
  %0 = tail call { i64, i1 } @llvm.sadd.with.overflow.i64(i64 %a, i64 %b), !nosanitize !2
  %1 = extractvalue { i64, i1 } %0, 1, !nosanitize !2
  br i1 %1, label %trap, label %cont, !nosanitize !2

trap:                                             ; preds = %entry
  tail call void @llvm.trap() #3, !nosanitize !2
  unreachable, !nosanitize !2

cont:                                             ; preds = %entry
  %2 = extractvalue { i64, i1 } %0, 0, !nosanitize !2
  store i64 %2, ptr %c, align 8, !tbaa !7
  ret void
}

; Function Attrs: nounwind readnone speculatable willreturn
declare { i64, i1 } @llvm.sadd.with.overflow.i64(i64, i64) #1

attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { nounwind readnone speculatable willreturn }
attributes #2 = { cold noreturn nounwind }
attributes #3 = { noreturn nounwind }

!llvm.module.flags = !{!0}
!llvm.ident = !{!1}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"clang version 11.0.0 (https://github.com/llvm/llvm-project.git 576fa5a50c8509977835031d190f8906e1dbb075)"}
!2 = !{}
!3 = !{!4, !4, i64 0}
!4 = !{!"int", !5, i64 0}
!5 = !{!"omnipotent char", !6, i64 0}
!6 = !{!"Simple C/C++ TBAA"}
!7 = !{!8, !8, i64 0}
!8 = !{!"long", !5, i64 0}
