File: split-gep-sub.ll

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; cs: 573
file content (77 lines) | stat: -rw-r--r-- 2,753 bytes parent folder | download | duplicates (10)
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
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -passes="separate-const-offset-from-gep<lower-gep>" < %s | FileCheck %s

; Check that GEP with an index 'A - B + [ConstantInt]' will be split into two
; GEPs. eg.
;     %A = ...
;     %B = ...
;     %sub = %A - %B
;     %idx = %sub + 10
;     %gep = getelementptr int, ptr %p, %idx
;  will be transformed into:
;     %A = ...
;     %B = ...
;     %sub = %A - %B
;     %gep_base = getelementptr int, ptr %p, %sub
;     %gep = getelementptr int, ptr %gep_base, 10

define void @test_A_sub_B_add_ConstantInt(ptr %p) {
; CHECK-LABEL: @test_A_sub_B_add_ConstantInt(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[TMP0:%.*]] = tail call i32 @foo()
; CHECK-NEXT:    [[REM:%.*]] = srem i32 [[TMP0]], 5
; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
; CHECK:       for.body:
; CHECK-NEXT:    [[K:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[COND_END:%.*]] ]
; CHECK-NEXT:    [[MUL:%.*]] = mul nuw nsw i32 [[K]], 5
; CHECK-NEXT:    [[SUB1:%.*]] = sub nsw i32 [[MUL]], [[REM]]
; CHECK-NEXT:    [[CMP26:%.*]] = icmp ult i32 [[SUB1]], 512
; CHECK-NEXT:    br i1 [[CMP26]], label [[COND_TRUE:%.*]], label [[COND_END]]
; CHECK:       cond.true:
; CHECK-NEXT:    [[TMP1:%.*]] = sext i32 [[MUL]] to i64
; CHECK-NEXT:    [[TMP2:%.*]] = sext i32 [[REM]] to i64
; CHECK-NEXT:    [[SUB22:%.*]] = sub i64 [[TMP2]], [[TMP1]]
; CHECK-NEXT:    [[TMP3:%.*]] = ptrtoint ptr [[P:%.*]] to i64
; CHECK-NEXT:    [[TMP4:%.*]] = shl i64 [[SUB22]], 2
; CHECK-NEXT:    [[TMP5:%.*]] = add i64 [[TMP3]], [[TMP4]]
; CHECK-NEXT:    [[TMP6:%.*]] = add i64 [[TMP5]], 2044
; CHECK-NEXT:    [[TMP7:%.*]] = inttoptr i64 [[TMP6]] to ptr
; CHECK-NEXT:    store float 1.000000e+00, ptr [[TMP7]], align 4
; CHECK-NEXT:    br label [[COND_END]]
; CHECK:       cond.end:
; CHECK-NEXT:    [[INC]] = add nuw nsw i32 [[K]], 1
; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp ne i32 [[INC]], 100
; CHECK-NEXT:    br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END:%.*]]
; CHECK:       for.end:
; CHECK-NEXT:    ret void
;
entry:
  %0 = tail call i32 @foo()
  %rem = srem i32 %0, 5
  %add = add nsw i32 %rem , 511
  br label %for.body

for.body:
  %k = phi i32 [ 0, %entry ], [ %inc, %cond.end ]
  %mul = mul nuw nsw i32 %k, 5
  %sub1 = sub nsw i32 %mul, %rem
  %cmp26 = icmp ult i32 %sub1, 512
  br i1 %cmp26, label %cond.true, label %cond.end

cond.true:
  %sub2 = sub nsw i32 %add, %mul
  %idxprom = sext i32 %sub2 to i64
  %arryidx = getelementptr inbounds float, ptr %p, i64 %idxprom
  store float 1.0, ptr %arryidx, align 4
  br label %cond.end

cond.end:
  %inc = add nuw nsw i32 %k, 1
  %exitcond = icmp ne i32 %inc, 100
  br i1 %exitcond, label %for.body, label %for.end

for.end:
  ret void
}

declare i32 @foo()