preserve-memoryssa.ll 2.78 KB
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt  -aa-pipeline=basic-aa -passes='require<memoryssa>,gvn' -S -verify-memoryssa %s | FileCheck %s

; REQUIRES: asserts

declare void @use(i32) readnone

define i32 @test(i32* %ptr.0, i32** %ptr.1, i1 %c) {
; CHECK-LABEL: @test(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[LV_0:%.*]] = load i32, i32* [[PTR_0:%.*]], align 8
; CHECK-NEXT:    call void @use(i32 [[LV_0]])
; CHECK-NEXT:    br i1 [[C:%.*]], label [[IF_THEN749:%.*]], label [[FOR_INC774:%.*]]
; CHECK:       if.then749:
; CHECK-NEXT:    [[LV_1:%.*]] = load i32*, i32** [[PTR_1:%.*]], align 8
; CHECK-NEXT:    store i32 10, i32* [[LV_1]], align 4
; CHECK-NEXT:    [[LV_2_PRE:%.*]] = load i32, i32* [[PTR_0]], align 8
; CHECK-NEXT:    br label [[FOR_INC774]]
; CHECK:       for.inc774:
; CHECK-NEXT:    [[LV_2:%.*]] = phi i32 [ [[LV_2_PRE]], [[IF_THEN749]] ], [ [[LV_0]], [[ENTRY:%.*]] ]
; CHECK-NEXT:    call void @use(i32 [[LV_2]])
; CHECK-NEXT:    ret i32 1
;
entry:
  br label %for.end435

for.end435:
  %lv.0 = load i32, i32* %ptr.0, align 8
  call void @use(i32 %lv.0)
  br label %if.end724

if.end724:
  br i1 %c, label %if.then749, label %for.inc774

if.then749:
  %lv.1 = load i32*, i32** %ptr.1, align 8
  %arrayidx772 = getelementptr inbounds i32, i32* %lv.1, i64 0
  store i32 10, i32* %arrayidx772, align 4
  br label %for.inc774

for.inc774:
  br label %for.body830

for.body830:
  %lv.2 = load i32, i32* %ptr.0, align 8
  call void @use(i32 %lv.2)
  br label %for.body.i22

for.body.i22:
  ret i32 1
}

define i32 @test_volatile(i32* %ptr.0, i32** %ptr.1, i1 %c) {
; CHECK-LABEL: @test_volatile(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[LV_0:%.*]] = load volatile i32, i32* [[PTR_0:%.*]], align 8
; CHECK-NEXT:    call void @use(i32 [[LV_0]])
; CHECK-NEXT:    br i1 [[C:%.*]], label [[IF_THEN749:%.*]], label [[FOR_INC774:%.*]]
; CHECK:       if.then749:
; CHECK-NEXT:    [[LV_1:%.*]] = load volatile i32*, i32** [[PTR_1:%.*]], align 8
; CHECK-NEXT:    store i32 10, i32* [[LV_1]], align 4
; CHECK-NEXT:    br label [[FOR_INC774]]
; CHECK:       for.inc774:
; CHECK-NEXT:    [[LV_2:%.*]] = load volatile i32, i32* [[PTR_0]], align 8
; CHECK-NEXT:    call void @use(i32 [[LV_2]])
; CHECK-NEXT:    ret i32 1
;
entry:
  br label %for.end435

for.end435:
  %lv.0 = load volatile i32, i32* %ptr.0, align 8
  call void @use(i32 %lv.0)
  br label %if.end724

if.end724:
  br i1 %c, label %if.then749, label %for.inc774

if.then749:
  %lv.1 = load volatile i32*, i32** %ptr.1, align 8
  %arrayidx772 = getelementptr inbounds i32, i32* %lv.1, i64 0
  store i32 10, i32* %arrayidx772, align 4
  br label %for.inc774

for.inc774:
  br label %for.body830

for.body830:
  %lv.2 = load volatile i32, i32* %ptr.0, align 8
  call void @use(i32 %lv.2)
  br label %for.body.i22

for.body.i22:
  ret i32 1
}