1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -instsimplify -S | FileCheck %s
3
4@g = external global i16, align 1
5@g2 = external global i16, align 1
6
7define i64 @ptrdiff1() {
8; CHECK-LABEL: @ptrdiff1(
9; CHECK-NEXT:    ret i64 sub (i64 ptrtoint (i16* @g to i64), i64 ptrtoint (i16* @g2 to i64))
10;
11  %i = ptrtoint i16* @g to i64
12  %i2 = ptrtoint i16* @g2 to i64
13  %diff = sub i64 %i, %i2
14  %r = freeze i64 %diff
15  ret i64 %r
16}
17
18define i64 @ptrdiff2() {
19; CHECK-LABEL: @ptrdiff2(
20; CHECK-NEXT:    ret i64 -2
21;
22  %i = ptrtoint i16* @g to i64
23  %gep = getelementptr i16, i16* @g, i64 1
24  %i2 = ptrtoint i16* %gep to i64
25  %diff = sub i64 %i, %i2
26  %r = freeze i64 %diff
27  ret i64 %r
28}
29