llvm/llvm/test/Transforms/DeadStoreElimination/malloc-earliest-escape-info-invalidation.ll

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
; RUN: opt -p dse -S %s | FileCheck %s

target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64"

define void @widget(ptr %a) {
; CHECK-LABEL: define void @widget(
; CHECK-SAME: ptr [[A:%.*]]) {
; CHECK-NEXT:  bb:
; CHECK-NEXT:    [[CALL1:%.*]] = tail call noalias ptr @malloc(i64 0)
; CHECK-NEXT:    store ptr [[CALL1]], ptr [[A]], align 8
; CHECK-NEXT:    [[LOAD:%.*]] = load ptr, ptr [[A]], align 8
; CHECK-NEXT:    [[LOAD2:%.*]] = load i32, ptr [[LOAD]], align 8
; CHECK-NEXT:    [[GETELEMENTPTR:%.*]] = getelementptr i8, ptr [[CALL1]], i64 0
; CHECK-NEXT:    [[GETELEMENTPTR3:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR]], i64 1
; CHECK-NEXT:    [[GETELEMENTPTR4:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR]], i64 8
; CHECK-NEXT:    store i16 0, ptr [[GETELEMENTPTR4]], align 4
; CHECK-NEXT:    [[GETELEMENTPTR5:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR]], i64 12
; CHECK-NEXT:    store i32 0, ptr [[CALL1]], align 4
; CHECK-NEXT:    [[LOAD6:%.*]] = load i32, ptr inttoptr (i64 4 to ptr), align 4
; CHECK-NEXT:    br label [[BB48:%.*]]
; CHECK:       bb7:
; CHECK-NEXT:    br label [[BB9:%.*]]
; CHECK:       bb8:
; CHECK-NEXT:    br label [[BB53:%.*]]
; CHECK:       bb9:
; CHECK-NEXT:    [[PHI:%.*]] = phi ptr [ [[CALL1]], [[BB7:%.*]] ], [ [[A]], [[BB43:%.*]] ]
; CHECK-NEXT:    [[GETELEMENTPTR10:%.*]] = getelementptr i8, ptr [[PHI]], i64 0
; CHECK-NEXT:    [[GETELEMENTPTR11:%.*]] = getelementptr i8, ptr [[PHI]], i64 0
; CHECK-NEXT:    [[GETELEMENTPTR12:%.*]] = getelementptr i8, ptr [[PHI]], i64 0
; CHECK-NEXT:    [[GETELEMENTPTR13:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR12]], i64 1
; CHECK-NEXT:    store i8 0, ptr [[CALL1]], align 1
; CHECK-NEXT:    br label [[BB29:%.*]]
; CHECK:       bb14:
; CHECK-NEXT:    [[GETELEMENTPTR15:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR10]], i64 8
; CHECK-NEXT:    [[LOAD16:%.*]] = load i16, ptr [[CALL1]], align 4
; CHECK-NEXT:    br i1 false, label [[BB22:%.*]], label [[BB17:%.*]]
; CHECK:       bb17:
; CHECK-NEXT:    [[GETELEMENTPTR18:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR11]], i64 8
; CHECK-NEXT:    [[LOAD19:%.*]] = load i16, ptr [[CALL1]], align 4
; CHECK-NEXT:    [[GETELEMENTPTR20:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR12]], i64 8
; CHECK-NEXT:    store i16 0, ptr [[CALL1]], align 4
; CHECK-NEXT:    [[GETELEMENTPTR21:%.*]] = getelementptr i8, ptr [[PHI]], i64 0
; CHECK-NEXT:    br label [[BB25:%.*]]
; CHECK:       bb22:
; CHECK-NEXT:    [[GETELEMENTPTR23:%.*]] = getelementptr i8, ptr [[PHI]], i64 0
; CHECK-NEXT:    [[GETELEMENTPTR24:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR23]], i64 12
; CHECK-NEXT:    br label [[BB25]]
; CHECK:       bb25:
; CHECK-NEXT:    [[PHI26:%.*]] = phi ptr [ [[A]], [[BB17]] ], [ [[CALL1]], [[BB22]] ]
; CHECK-NEXT:    [[PHI27:%.*]] = phi ptr [ [[CALL1]], [[BB17]] ], [ [[CALL1]], [[BB22]] ]
; CHECK-NEXT:    [[PHI28:%.*]] = phi ptr [ [[CALL1]], [[BB17]] ], [ [[CALL1]], [[BB22]] ]
; CHECK-NEXT:    store i32 0, ptr [[CALL1]], align 4
; CHECK-NEXT:    br label [[BB29]]
; CHECK:       bb29:
; CHECK-NEXT:    [[PHI30:%.*]] = phi ptr [ [[CALL1]], [[BB9]] ], [ [[CALL1]], [[BB25]] ]
; CHECK-NEXT:    [[PHI31:%.*]] = phi ptr [ [[CALL1]], [[BB9]] ], [ [[CALL1]], [[BB25]] ]
; CHECK-NEXT:    [[LOAD32:%.*]] = load i8, ptr [[CALL1]], align 4
; CHECK-NEXT:    [[LOAD33:%.*]] = load i8, ptr [[CALL1]], align 4
; CHECK-NEXT:    [[GETELEMENTPTR34:%.*]] = getelementptr i8, ptr [[PHI31]], i64 12
; CHECK-NEXT:    [[GETELEMENTPTR35:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR12]], i64 12
; CHECK-NEXT:    br label [[BB86:%.*]]
; CHECK:       bb36:
; CHECK-NEXT:    [[GETELEMENTPTR37:%.*]] = getelementptr i8, ptr [[PHI30]], i64 12
; CHECK-NEXT:    br label [[BB38:%.*]]
; CHECK:       bb38:
; CHECK-NEXT:    [[GETELEMENTPTR39:%.*]] = getelementptr [0 x i32], ptr [[GETELEMENTPTR34]], i64 0, i64 0
; CHECK-NEXT:    [[LOAD40:%.*]] = load i32, ptr [[CALL1]], align 4
; CHECK-NEXT:    [[GETELEMENTPTR41:%.*]] = getelementptr [0 x i32], ptr [[GETELEMENTPTR37]], i64 0, i64 0
; CHECK-NEXT:    [[LOAD42:%.*]] = load i32, ptr [[CALL1]], align 4
; CHECK-NEXT:    br label [[BB38]]
; CHECK:       bb43:
; CHECK-NEXT:    [[GETELEMENTPTR44:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR12]], i64 8
; CHECK-NEXT:    [[LOAD45:%.*]] = load i16, ptr [[CALL1]], align 4
; CHECK-NEXT:    store i16 0, ptr [[CALL1]], align 4
; CHECK-NEXT:    store i8 0, ptr [[CALL1]], align 4
; CHECK-NEXT:    [[GETELEMENTPTR46:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR12]], i64 12
; CHECK-NEXT:    store i32 0, ptr [[CALL1]], align 4
; CHECK-NEXT:    [[GETELEMENTPTR47:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR12]], i64 16
; CHECK-NEXT:    store i32 0, ptr [[CALL1]], align 4
; CHECK-NEXT:    br label [[BB9]]
; CHECK:       bb48:
; CHECK-NEXT:    [[GETELEMENTPTR49:%.*]] = getelementptr i8, ptr [[CALL1]], i64 0
; CHECK-NEXT:    [[GETELEMENTPTR50:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR49]], i64 1
; CHECK-NEXT:    [[GETELEMENTPTR51:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR49]], i64 8
; CHECK-NEXT:    [[GETELEMENTPTR52:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR49]], i64 12
; CHECK-NEXT:    store i32 0, ptr [[CALL1]], align 4
; CHECK-NEXT:    br label [[BB48]]
; CHECK:       bb53:
; CHECK-NEXT:    [[PHI54:%.*]] = phi ptr [ [[CALL1]], [[BB8:%.*]] ], [ [[A]], [[BB71:%.*]] ]
; CHECK-NEXT:    [[GETELEMENTPTR55:%.*]] = getelementptr i8, ptr [[PHI54]], i64 0
; CHECK-NEXT:    [[GETELEMENTPTR56:%.*]] = getelementptr i8, ptr [[PHI54]], i64 0
; CHECK-NEXT:    [[GETELEMENTPTR57:%.*]] = getelementptr i8, ptr [[PHI54]], i64 0
; CHECK-NEXT:    [[GETELEMENTPTR58:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR57]], i64 1
; CHECK-NEXT:    br label [[BB71]]
; CHECK:       bb59:
; CHECK-NEXT:    [[GETELEMENTPTR60:%.*]] = getelementptr i8, ptr [[PHI54]], i64 0
; CHECK-NEXT:    [[GETELEMENTPTR61:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR60]], i64 12
; CHECK-NEXT:    br label [[BB67:%.*]]
; CHECK:       bb62:
; CHECK-NEXT:    [[GETELEMENTPTR63:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR56]], i64 8
; CHECK-NEXT:    [[LOAD64:%.*]] = load i16, ptr [[CALL1]], align 4
; CHECK-NEXT:    [[GETELEMENTPTR65:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR57]], i64 8
; CHECK-NEXT:    store i16 0, ptr [[CALL1]], align 4
; CHECK-NEXT:    [[GETELEMENTPTR66:%.*]] = getelementptr i8, ptr [[PHI54]], i64 0
; CHECK-NEXT:    br label [[BB67]]
; CHECK:       bb67:
; CHECK-NEXT:    [[PHI68:%.*]] = phi ptr [ [[A]], [[BB62:%.*]] ], [ [[CALL1]], [[BB59:%.*]] ]
; CHECK-NEXT:    [[PHI69:%.*]] = phi ptr [ [[CALL1]], [[BB62]] ], [ [[CALL1]], [[BB59]] ]
; CHECK-NEXT:    [[PHI70:%.*]] = phi ptr [ [[CALL1]], [[BB62]] ], [ [[CALL1]], [[BB59]] ]
; CHECK-NEXT:    store i32 0, ptr [[CALL1]], align 4
; CHECK-NEXT:    br label [[BB71]]
; CHECK:       bb71:
; CHECK-NEXT:    [[PHI72:%.*]] = phi ptr [ [[CALL1]], [[BB53]] ], [ [[CALL1]], [[BB67]] ]
; CHECK-NEXT:    [[PHI73:%.*]] = phi ptr [ [[CALL1]], [[BB53]] ], [ [[CALL1]], [[BB67]] ]
; CHECK-NEXT:    [[LOAD74:%.*]] = load i8, ptr [[CALL1]], align 4
; CHECK-NEXT:    [[LOAD75:%.*]] = load i8, ptr [[CALL1]], align 4
; CHECK-NEXT:    [[GETELEMENTPTR76:%.*]] = getelementptr i8, ptr [[PHI72]], i64 12
; CHECK-NEXT:    [[GETELEMENTPTR77:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR57]], i64 12
; CHECK-NEXT:    [[GETELEMENTPTR78:%.*]] = getelementptr [0 x i32], ptr [[GETELEMENTPTR76]], i64 0, i64 0
; CHECK-NEXT:    [[LOAD79:%.*]] = load i32, ptr [[CALL1]], align 4
; CHECK-NEXT:    [[GETELEMENTPTR80:%.*]] = getelementptr [0 x i32], ptr [[GETELEMENTPTR77]], i64 0, i64 0
; CHECK-NEXT:    store i32 0, ptr [[CALL1]], align 4
; CHECK-NEXT:    [[LOAD81:%.*]] = load i8, ptr [[CALL1]], align 4
; CHECK-NEXT:    [[GETELEMENTPTR82:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR57]], i64 8
; CHECK-NEXT:    [[LOAD83:%.*]] = load i16, ptr [[CALL1]], align 4
; CHECK-NEXT:    store i16 0, ptr [[CALL1]], align 4
; CHECK-NEXT:    store i8 0, ptr [[CALL1]], align 4
; CHECK-NEXT:    [[GETELEMENTPTR84:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR57]], i64 12
; CHECK-NEXT:    store i32 0, ptr [[CALL1]], align 4
; CHECK-NEXT:    [[GETELEMENTPTR85:%.*]] = getelementptr i8, ptr [[GETELEMENTPTR57]], i64 16
; CHECK-NEXT:    store i32 0, ptr [[CALL1]], align 4
; CHECK-NEXT:    br label [[BB53]]
; CHECK:       bb86:
; CHECK-NEXT:    [[GETELEMENTPTR87:%.*]] = getelementptr [0 x i32], ptr [[GETELEMENTPTR34]], i64 0, i64 0
; CHECK-NEXT:    [[LOAD88:%.*]] = load i32, ptr [[CALL1]], align 4
; CHECK-NEXT:    [[GETELEMENTPTR89:%.*]] = getelementptr [0 x i32], ptr [[GETELEMENTPTR35]], i64 0, i64 0
; CHECK-NEXT:    store i32 0, ptr [[CALL1]], align 4
; CHECK-NEXT:    br label [[BB86]]
;
bb:
  %call = tail call ptr @malloc(i64 1)
  tail call void @llvm.memset.p0.i64(ptr %call, i8 0, i64 1, i1 false)
  %call1 = tail call noalias ptr @malloc(i64 0)
  store ptr %call1, ptr %a, align 8
  %load = load ptr, ptr %a, align 8
  %load2 = load i32, ptr %load, align 8
  %getelementptr = getelementptr i8, ptr %call1, i64 0
  %getelementptr3 = getelementptr i8, ptr %getelementptr, i64 1
  store i8 0, ptr %call1, align 1
  %getelementptr4 = getelementptr i8, ptr %getelementptr, i64 8
  store i16 0, ptr %getelementptr4, align 4
  %getelementptr5 = getelementptr i8, ptr %getelementptr, i64 12
  store i32 0, ptr %call1, align 4
  %load6 = load i32, ptr inttoptr (i64 4 to ptr), align 4
  br label %bb48

bb7:                                              ; No predecessors!
  br label %bb9

bb8:                                              ; No predecessors!
  br label %bb53

bb9:                                              ; preds = %bb43, %bb7
  %phi = phi ptr [ %call1, %bb7 ], [ %a, %bb43 ]
  %getelementptr10 = getelementptr i8, ptr %phi, i64 0
  %getelementptr11 = getelementptr i8, ptr %phi, i64 0
  %getelementptr12 = getelementptr i8, ptr %phi, i64 0
  %getelementptr13 = getelementptr i8, ptr %getelementptr12, i64 1
  store i8 0, ptr %call1, align 1
  br label %bb29

bb14:                                             ; No predecessors!
  %getelementptr15 = getelementptr i8, ptr %getelementptr10, i64 8
  %load16 = load i16, ptr %call1, align 4
  br i1 false, label %bb22, label %bb17

bb17:                                             ; preds = %bb14
  %getelementptr18 = getelementptr i8, ptr %getelementptr11, i64 8
  %load19 = load i16, ptr %call1, align 4
  %getelementptr20 = getelementptr i8, ptr %getelementptr12, i64 8
  store i16 0, ptr %call1, align 4
  %getelementptr21 = getelementptr i8, ptr %phi, i64 0
  br label %bb25

bb22:                                             ; preds = %bb14
  %getelementptr23 = getelementptr i8, ptr %phi, i64 0
  %getelementptr24 = getelementptr i8, ptr %getelementptr23, i64 12
  br label %bb25

bb25:                                             ; preds = %bb22, %bb17
  %phi26 = phi ptr [ %a, %bb17 ], [ %call1, %bb22 ]
  %phi27 = phi ptr [ %call1, %bb17 ], [ %call1, %bb22 ]
  %phi28 = phi ptr [ %call1, %bb17 ], [ %call1, %bb22 ]
  store i32 0, ptr %call1, align 4
  br label %bb29

bb29:                                             ; preds = %bb25, %bb9
  %phi30 = phi ptr [ %call1, %bb9 ], [ %call1, %bb25 ]
  %phi31 = phi ptr [ %call1, %bb9 ], [ %call1, %bb25 ]
  %load32 = load i8, ptr %call1, align 4
  %load33 = load i8, ptr %call1, align 4
  %getelementptr34 = getelementptr i8, ptr %phi31, i64 12
  %getelementptr35 = getelementptr i8, ptr %getelementptr12, i64 12
  br label %bb86

bb36:                                             ; No predecessors!
  %getelementptr37 = getelementptr i8, ptr %phi30, i64 12
  br label %bb38

bb38:                                             ; preds = %bb38, %bb36
  %getelementptr39 = getelementptr [0 x i32], ptr %getelementptr34, i64 0, i64 0
  %load40 = load i32, ptr %call1, align 4
  %getelementptr41 = getelementptr [0 x i32], ptr %getelementptr37, i64 0, i64 0
  %load42 = load i32, ptr %call1, align 4
  br label %bb38

bb43:                                             ; No predecessors!
  %getelementptr44 = getelementptr i8, ptr %getelementptr12, i64 8
  %load45 = load i16, ptr %call1, align 4
  store i16 0, ptr %call1, align 4
  store i8 0, ptr %call1, align 4
  %getelementptr46 = getelementptr i8, ptr %getelementptr12, i64 12
  store i32 0, ptr %call1, align 4
  %getelementptr47 = getelementptr i8, ptr %getelementptr12, i64 16
  store i32 0, ptr %call1, align 4
  br label %bb9

bb48:                                             ; preds = %bb48, %bb
  %getelementptr49 = getelementptr i8, ptr %call1, i64 0
  %getelementptr50 = getelementptr i8, ptr %getelementptr49, i64 1
  store i8 0, ptr %call1, align 1
  %getelementptr51 = getelementptr i8, ptr %getelementptr49, i64 8
  store i16 0, ptr %call1, align 4
  %getelementptr52 = getelementptr i8, ptr %getelementptr49, i64 12
  store i32 0, ptr %call1, align 4
  br label %bb48

bb53:                                             ; preds = %bb71, %bb8
  %phi54 = phi ptr [ %call1, %bb8 ], [ %a, %bb71 ]
  %getelementptr55 = getelementptr i8, ptr %phi54, i64 0
  %getelementptr56 = getelementptr i8, ptr %phi54, i64 0
  %getelementptr57 = getelementptr i8, ptr %phi54, i64 0
  %getelementptr58 = getelementptr i8, ptr %getelementptr57, i64 1
  br label %bb71

bb59:                                             ; No predecessors!
  %getelementptr60 = getelementptr i8, ptr %phi54, i64 0
  %getelementptr61 = getelementptr i8, ptr %getelementptr60, i64 12
  br label %bb67

bb62:                                             ; No predecessors!
  %getelementptr63 = getelementptr i8, ptr %getelementptr56, i64 8
  %load64 = load i16, ptr %call1, align 4
  %getelementptr65 = getelementptr i8, ptr %getelementptr57, i64 8
  store i16 0, ptr %call1, align 4
  %getelementptr66 = getelementptr i8, ptr %phi54, i64 0
  br label %bb67

bb67:                                             ; preds = %bb62, %bb59
  %phi68 = phi ptr [ %a, %bb62 ], [ %call1, %bb59 ]
  %phi69 = phi ptr [ %call1, %bb62 ], [ %call1, %bb59 ]
  %phi70 = phi ptr [ %call1, %bb62 ], [ %call1, %bb59 ]
  store i32 0, ptr %call1, align 4
  br label %bb71

bb71:                                             ; preds = %bb67, %bb53
  %phi72 = phi ptr [ %call1, %bb53 ], [ %call1, %bb67 ]
  %phi73 = phi ptr [ %call1, %bb53 ], [ %call1, %bb67 ]
  %load74 = load i8, ptr %call1, align 4
  %load75 = load i8, ptr %call1, align 4
  %getelementptr76 = getelementptr i8, ptr %phi72, i64 12
  %getelementptr77 = getelementptr i8, ptr %getelementptr57, i64 12
  %getelementptr78 = getelementptr [0 x i32], ptr %getelementptr76, i64 0, i64 0
  %load79 = load i32, ptr %call1, align 4
  %getelementptr80 = getelementptr [0 x i32], ptr %getelementptr77, i64 0, i64 0
  store i32 0, ptr %call1, align 4
  %load81 = load i8, ptr %call1, align 4
  %getelementptr82 = getelementptr i8, ptr %getelementptr57, i64 8
  %load83 = load i16, ptr %call1, align 4
  store i16 0, ptr %call1, align 4
  store i8 0, ptr %call1, align 4
  %getelementptr84 = getelementptr i8, ptr %getelementptr57, i64 12
  store i32 0, ptr %call1, align 4
  %getelementptr85 = getelementptr i8, ptr %getelementptr57, i64 16
  store i32 0, ptr %call1, align 4
  br label %bb53

bb86:                                             ; preds = %bb86, %bb29
  %getelementptr87 = getelementptr [0 x i32], ptr %getelementptr34, i64 0, i64 0
  %load88 = load i32, ptr %call1, align 4
  %getelementptr89 = getelementptr [0 x i32], ptr %getelementptr35, i64 0, i64 0
  store i32 0, ptr %call1, align 4
  br label %bb86
}

declare ptr @malloc(i64)

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }