File: gep-implicit-trunc-32-bit-pointers.ll

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (93 lines) | stat: -rw-r--r-- 3,174 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
; RUN: opt -basic-aa -aa-eval -print-all-alias-modref-info -disable-output %s 2>&1 | FileCheck %s

target datalayout = "p:32:32:32"

; Test cases with i64 bit GEP indices that will get truncated implicitly to 32
; bit due to the datalayout.

declare void @llvm.assume(i1)

define void @mustalias_overflow_in_32_bit_constants(i8* %ptr) {
; CHECK-LABEL: Function: mustalias_overflow_in_32_bit_constants: 3 pointers, 0 call sites
; CHECK-NEXT:    MustAlias: i8* %gep.1, i8* %ptr
; CHECK-NEXT:    MustAlias:    i8* %gep.2, i8* %ptr
; CHECK-NEXT:    MustAlias:    i8* %gep.1, i8* %gep.2
;
  %gep.1 = getelementptr i8, i8* %ptr, i64 4294967296
  store i8 0, i8* %gep.1
  %gep.2 = getelementptr i8, i8* %ptr, i64 0
  store i8 1, i8* %gep.2
  ret void
}

define void @mustalias_overflow_in_32_with_var_index([1 x i8]* %ptr, i64 %n) {
; CHECK-LABEL: Function: mustalias_overflow_in_32_with_var_index
; CHECK:       MustAlias: i8* %gep.1, i8* %gep.2
;
  %gep.1 = getelementptr [1 x i8], [1 x i8]* %ptr, i64 %n, i64 4294967296
  store i8 0, i8* %gep.1
  %gep.2 = getelementptr [1 x i8], [1 x i8]* %ptr, i64 %n, i64 0
  store i8 1, i8* %gep.2
  ret void
}

define void @noalias_overflow_in_32_bit_constants(i8* %ptr) {
; CHECK-LABEL: Function: noalias_overflow_in_32_bit_constants: 3 pointers, 0 call sites
; CHECK-NEXT:    MustAlias: i8* %gep.1, i8* %ptr
; CHECK-NEXT:    NoAlias:  i8* %gep.2, i8* %ptr
; CHECK-NEXT:    NoAlias:  i8* %gep.1, i8* %gep.2
;
  %gep.1 = getelementptr i8, i8* %ptr, i64 4294967296
  store i8 0, i8* %gep.1
  %gep.2 = getelementptr i8, i8* %ptr, i64 1
  store i8 1, i8* %gep.2
  ret void
}

; The GEP indices get implicitly truncated to 32 bit, so multiples of 2^32
; (=4294967296) will be 0.
; See https://alive2.llvm.org/ce/z/HHjQgb.
define void @mustalias_overflow_in_32_bit_add_mul_gep(i8* %ptr, i64 %i) {
; CHECK-LABEL: Function: mustalias_overflow_in_32_bit_add_mul_gep: 3 pointers, 1 call sites
; CHECK-NEXT:    MayAlias: i8* %gep.1, i8* %ptr
; CHECK-NEXT:    MayAlias: i8* %gep.2, i8* %ptr
; CHECK-NEXT:    MayAlias: i8* %gep.1, i8* %gep.2
;
  %s.1 = icmp sgt i64 %i, 0
  call void @llvm.assume(i1 %s.1)

  %mul = mul nuw nsw i64 %i, 4294967296
  %add = add nuw nsw i64 %mul, %i
  %gep.1 = getelementptr i8, i8* %ptr, i64 %add
  store i8 0, i8* %gep.1
  %gep.2 = getelementptr i8, i8* %ptr, i64 %i
  store i8 1, i8* %gep.2
  ret void
}

define void @mayalias_overflow_in_32_bit_non_zero(i8* %ptr, i64 %n) {
; CHECK-LABEL: Function: mayalias_overflow_in_32_bit_non_zero
; CHECK:    MayAlias: i8* %gep, i8* %ptr
;
  %c = icmp ne i64 %n, 0
  call void @llvm.assume(i1 %c)
  store i8 0, i8* %ptr
  %gep = getelementptr i8, i8* %ptr, i64 %n
  store i8 1, i8* %gep
  ret void
}

define void @mayalias_overflow_in_32_bit_positive(i8* %ptr, i64 %n) {
; CHECK-LABEL: Function: mayalias_overflow_in_32_bit_positive
; CHECK:    NoAlias: i8* %gep.1, i8* %ptr
; CHECK:    MayAlias: i8* %gep.2, i8* %ptr
; CHECK:    MayAlias: i8* %gep.1, i8* %gep.2
;
  %c = icmp sgt i64 %n, 0
  call void @llvm.assume(i1 %c)
  %gep.1 = getelementptr i8, i8* %ptr, i64 -1
  store i8 0, i8* %gep.1
  %gep.2 = getelementptr i8, i8* %ptr, i64 %n
  store i8 1, i8* %gep.2
  ret void
}