1; RUN: opt -S -reassociate -die < %s | FileCheck %s
2
3; The two va_arg instructions depend on the memory/context, are therfore not
4; identical and the sub should not be optimized to 0 by reassociate.
5;
6; CHECK-LABEL: @func(
7; ...
8; CHECK: %v0 = va_arg i8** %varargs, i32
9; CHECK: %v1 = va_arg i8** %varargs, i32
10; CHECK: %v0.neg = sub i32 0, %v0
11; CHECK: %sub = add i32 %v0.neg, 1
12; CHECK: %add = add i32 %sub, %v1
13; ...
14; CHECK: ret i32 %add
15define i32 @func(i32 %dummy, ...) {
16  %varargs = alloca i8*, align 8
17  %varargs1 = bitcast i8** %varargs to i8*
18  call void @llvm.va_start(i8* %varargs1)
19  %v0 = va_arg i8** %varargs, i32
20  %v1 = va_arg i8** %varargs, i32
21  %sub = sub nsw i32 %v1, %v0
22  %add = add nsw i32 %sub, 1
23  call void @llvm.va_end(i8* %varargs1)
24  ret i32 %add
25}
26
27declare void @llvm.va_start(i8*)
28declare void @llvm.va_end(i8*)
29