File: store-after-loop.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 (55 lines) | stat: -rw-r--r-- 2,731 bytes parent folder | download | duplicates (12)
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
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=dse -S | FileCheck %s

target datalayout = "E-m:e-p:32:32-i64:32-f64:32:64-a:0:32-n32-S32"

%struct.ilist = type { i32, ptr }

; There is no dead store in this test. Make sure no store is deleted by DSE.
; Test case related to bug report PR52774.

define ptr @test() {
; CHECK-LABEL: @test(
; CHECK-NEXT:    br label [[LOOP:%.*]]
; CHECK:       loop:
; CHECK-NEXT:    [[IV:%.*]] = phi i32 [ 0, [[TMP0:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
; CHECK-NEXT:    [[LIST_NEXT:%.*]] = phi ptr [ null, [[TMP0]] ], [ [[LIST_NEW_I8_PTR:%.*]], [[LOOP]] ]
; CHECK-NEXT:    [[LIST_NEW_I8_PTR]] = tail call align 8 dereferenceable_or_null(8) ptr @malloc(i32 8)
; CHECK-NEXT:    store i32 42, ptr [[LIST_NEW_I8_PTR]], align 8
; CHECK-NEXT:    [[GEP_NEW_NEXT:%.*]] = getelementptr inbounds [[STRUCT_ILIST:%.*]], ptr [[LIST_NEW_I8_PTR]], i32 0, i32 1
; CHECK-NEXT:    store ptr [[LIST_NEXT]], ptr [[GEP_NEW_NEXT]], align 4
; CHECK-NEXT:    [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
; CHECK-NEXT:    [[COND:%.*]] = icmp eq i32 [[IV_NEXT]], 10
; CHECK-NEXT:    br i1 [[COND]], label [[EXIT:%.*]], label [[LOOP]]
; CHECK:       exit:
; CHECK-NEXT:    [[GEP_LIST_LAST_NEXT:%.*]] = getelementptr inbounds [[STRUCT_ILIST]], ptr [[LIST_NEW_I8_PTR]], i32 0, i32 1
; CHECK-NEXT:    store ptr null, ptr [[GEP_LIST_LAST_NEXT]], align 4
; CHECK-NEXT:    [[GEP_LIST_NEXT_NEXT:%.*]] = getelementptr inbounds [[STRUCT_ILIST]], ptr [[LIST_NEXT]], i32 0, i32 1
; CHECK-NEXT:    [[LOADED_PTR:%.*]] = load ptr, ptr [[GEP_LIST_NEXT_NEXT]], align 4
; CHECK-NEXT:    ret ptr [[LOADED_PTR]]
;
  br label %loop

loop:
  %iv = phi i32 [ 0, %0 ], [ %iv.next, %loop ]
  %list.next = phi ptr [ null, %0 ], [ %list.new.i8.ptr, %loop ]
  %list.new.i8.ptr = tail call align 8 dereferenceable_or_null(8) ptr @malloc(i32 8)
  store i32 42, ptr %list.new.i8.ptr, align 8
  %gep.new.next = getelementptr inbounds %struct.ilist, ptr %list.new.i8.ptr, i32 0, i32 1
  store ptr %list.next, ptr %gep.new.next, align 4
  %iv.next = add nuw nsw i32 %iv, 1
  %cond = icmp eq i32 %iv.next, 10
  br i1 %cond, label %exit, label %loop

exit:
  %gep.list.last.next = getelementptr inbounds %struct.ilist, ptr %list.new.i8.ptr, i32 0, i32 1
  store ptr null, ptr %gep.list.last.next, align 4
  %gep.list.next.next = getelementptr inbounds %struct.ilist, ptr %list.next, i32 0, i32 1
  %loaded_ptr = load ptr, ptr %gep.list.next.next, align 4
  ret ptr %loaded_ptr                                      ; use loaded pointer
}

; Function Attrs: inaccessiblememonly nounwind
declare noalias noundef align 8 ptr @malloc(i32 noundef) local_unnamed_addr #0

attributes #0 = { inaccessiblememonly nounwind}