llvm/llvm/test/Transforms/PhaseOrdering/pr98799-inline-simplifycfg-ub.ll

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt < %s -passes=inline,simplifycfg -S | FileCheck --check-prefix=CUSTOM %s
; RUN: opt < %s -O2 -S | FileCheck --check-prefix=O2 %s

define internal ptr @bar(ptr %arg, i1 %arg1) {
bb:
  br i1 %arg1, label %bb4, label %bb2

bb2:
  %i = load ptr, ptr %arg, align 8
  %i3 = getelementptr inbounds i8, ptr %i, i64 1
  store ptr %i3, ptr %arg, align 8
  br label %bb4

bb4:
  %i5 = phi ptr [ %i, %bb2 ], [ null, %bb ]
  ret ptr %i5
}

define i32 @foo(ptr %arg, i1 %arg1) {
; CUSTOM-LABEL: define i32 @foo(
; CUSTOM-SAME: ptr [[ARG:%.*]], i1 [[ARG1:%.*]]) {
; CUSTOM-NEXT:  [[BB:.*:]]
; CUSTOM-NEXT:    [[TMP0:%.*]] = xor i1 [[ARG1]], true
; CUSTOM-NEXT:    call void @llvm.assume(i1 [[TMP0]])
; CUSTOM-NEXT:    [[I_I:%.*]] = load ptr, ptr [[ARG]], align 8
; CUSTOM-NEXT:    [[I3_I:%.*]] = getelementptr inbounds i8, ptr [[I_I]], i64 1
; CUSTOM-NEXT:    store ptr [[I3_I]], ptr [[ARG]], align 8
; CUSTOM-NEXT:    [[I2:%.*]] = icmp ne ptr [[I_I]], null
; CUSTOM-NEXT:    call void @llvm.assume(i1 [[I2]])
; CUSTOM-NEXT:    [[I3:%.*]] = load i32, ptr [[I_I]], align 4
; CUSTOM-NEXT:    ret i32 [[I3]]
;
; O2-LABEL: define i32 @foo(
; O2-SAME: ptr nocapture [[ARG:%.*]], i1 [[ARG1:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
; O2-NEXT:  [[BB:.*:]]
; O2-NEXT:    [[TMP0:%.*]] = xor i1 [[ARG1]], true
; O2-NEXT:    tail call void @llvm.assume(i1 [[TMP0]])
; O2-NEXT:    [[I_I:%.*]] = load ptr, ptr [[ARG]], align 8, !nonnull [[META0:![0-9]+]], !noundef [[META0]]
; O2-NEXT:    [[I3_I:%.*]] = getelementptr inbounds i8, ptr [[I_I]], i64 1
; O2-NEXT:    store ptr [[I3_I]], ptr [[ARG]], align 8
; O2-NEXT:    [[I3:%.*]] = load i32, ptr [[I_I]], align 4
; O2-NEXT:    ret i32 [[I3]]
;
bb:
  %i = call ptr @bar(ptr %arg, i1 %arg1)
  %i2 = icmp ne ptr %i, null
  call void @llvm.assume(i1 %i2)
  %i3 = load i32, ptr %i, align 4
  ret i32 %i3
}

declare void @llvm.assume(i1)
;.
; O2: [[META0]] = !{}
;.