1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=reassociate,dce < %s | FileCheck %s
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.
9 define i32 @func(i32 %dummy, ...) {
12 ; CHECK-NEXT: [[VARARGS:%.*]] = alloca ptr, align 8
13 ; CHECK-NEXT: call void @llvm.va_start.p0(ptr [[VARARGS]])
14 ; CHECK-NEXT: [[V0:%.*]] = va_arg ptr [[VARARGS]], i32
15 ; CHECK-NEXT: [[V1:%.*]] = va_arg ptr [[VARARGS]], i32
16 ; CHECK-NEXT: [[V0_NEG:%.*]] = sub i32 0, [[V0]]
17 ; CHECK-NEXT: [[SUB:%.*]] = add i32 [[V0_NEG]], 1
18 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[SUB]], [[V1]]
19 ; CHECK-NEXT: call void @llvm.va_end.p0(ptr [[VARARGS]])
20 ; CHECK-NEXT: ret i32 [[ADD]]
22 %varargs = alloca ptr, align 8
23 call void @llvm.va_start(ptr %varargs)
24 %v0 = va_arg ptr %varargs, i32
25 %v1 = va_arg ptr %varargs, i32
26 %sub = sub nsw i32 %v1, %v0
27 %add = add nsw i32 %sub, 1
28 call void @llvm.va_end(ptr %varargs)
32 declare void @llvm.va_start(ptr)
33 declare void @llvm.va_end(ptr)