reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    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
; RUN: opt -S -gvn-hoist < %s | FileCheck %s

; Check that the stores are not hoisted: it is invalid to hoist stores if they
; are not executed on all paths. In this testcase, there are paths in the loop
; that do not execute the stores.

; CHECK-LABEL: define i32 @main
; CHECK: store
; CHECK: store
; CHECK: store

@a = global i32 0, align 4

define i32 @main() {
entry:
  br label %for.cond

for.cond:                                         ; preds = %for.inc5, %entry
  %0 = load i32, i32* @a, align 4
  %cmp = icmp slt i32 %0, 1
  br i1 %cmp, label %for.cond1, label %for.end7

for.cond1:                                        ; preds = %for.cond, %for.inc
  %1 = load i32, i32* @a, align 4
  %cmp2 = icmp slt i32 %1, 1
  br i1 %cmp2, label %for.body3, label %for.inc5

for.body3:                                        ; preds = %for.cond1
  %tobool = icmp ne i32 %1, 0
  br i1 %tobool, label %if.then, label %for.inc

if.then:                                          ; preds = %for.body3
  %inc = add nsw i32 %1, 1
  store i32 %inc, i32* @a, align 4
  br label %for.inc

for.inc:                                          ; preds = %for.body3, %if.then
  %2 = load i32, i32* @a, align 4
  %inc4 = add nsw i32 %2, 1
  store i32 %inc4, i32* @a, align 4
  br label %for.cond1

for.inc5:                                         ; preds = %for.cond1
  %inc6 = add nsw i32 %1, 1
  store i32 %inc6, i32* @a, align 4
  br label %for.cond

for.end7:                                         ; preds = %for.cond
  ret i32 %0
}