• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -S -reassociate -dce < %s | FileCheck %s
3
4; The two va_arg instructions depend on the memory/context, are therfore not
5; identical and the sub should not be optimized to 0 by reassociate.
6;
7; ...
8; ...
9define i32 @func(i32 %dummy, ...) {
10;
11; CHECK-LABEL: @func(
12; CHECK-NEXT:    [[VARARGS:%.*]] = alloca i8*, align 8
13; CHECK-NEXT:    [[VARARGS1:%.*]] = bitcast i8** [[VARARGS]] to i8*
14; CHECK-NEXT:    call void @llvm.va_start(i8* [[VARARGS1]])
15; CHECK-NEXT:    [[V0:%.*]] = va_arg i8** [[VARARGS]], i32
16; CHECK-NEXT:    [[V1:%.*]] = va_arg i8** [[VARARGS]], i32
17; CHECK-NEXT:    [[V0_NEG:%.*]] = sub i32 0, [[V0]]
18; CHECK-NEXT:    [[SUB:%.*]] = add i32 [[V0_NEG]], 1
19; CHECK-NEXT:    [[ADD:%.*]] = add i32 [[SUB]], [[V1]]
20; CHECK-NEXT:    call void @llvm.va_end(i8* [[VARARGS1]])
21; CHECK-NEXT:    ret i32 [[ADD]]
22;
23  %varargs = alloca i8*, align 8
24  %varargs1 = bitcast i8** %varargs to i8*
25  call void @llvm.va_start(i8* %varargs1)
26  %v0 = va_arg i8** %varargs, i32
27  %v1 = va_arg i8** %varargs, i32
28  %sub = sub nsw i32 %v1, %v0
29  %add = add nsw i32 %sub, 1
30  call void @llvm.va_end(i8* %varargs1)
31  ret i32 %add
32}
33
34declare void @llvm.va_start(i8*)
35declare void @llvm.va_end(i8*)
36