Skip to content

Commit

Permalink
[LICM] Add test for PR51248.
Browse files Browse the repository at this point in the history
Test for #51248. LICM introduces an unused load in a writeonly function.
  • Loading branch information
fhahn committed Apr 10, 2022
1 parent 9a63978 commit b42c054
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions llvm/test/Transforms/LICM/scalar-promote.ll
Expand Up @@ -599,6 +599,65 @@ Out:

}

@glb = external global i8, align 1

; Test case for PR51248.
define void @test_sink_store_only(i8 %var, i64 %start) writeonly {
; CHECK-LABEL: @test_sink_store_only(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[DIV:%.*]] = sdiv i8 [[VAR:%.*]], 3
; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i8 [[DIV]], 0
; CHECK-NEXT: [[GLB_PROMOTED:%.*]] = load i8, i8* @glb, align 1
; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
; CHECK: loop.header:
; CHECK-NEXT: [[MERGE1:%.*]] = phi i8 [ [[GLB_PROMOTED]], [[ENTRY:%.*]] ], [ [[MERGE:%.*]], [[LOOP_LATCH:%.*]] ]
; CHECK-NEXT: [[I:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[ADD:%.*]], [[LOOP_LATCH]] ]
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[I]], 4
; CHECK-NEXT: br i1 [[CMP]], label [[LOOP_BODY:%.*]], label [[FOR_END:%.*]]
; CHECK: loop.body:
; CHECK-NEXT: br i1 [[CMP2]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]
; CHECK: cond.true:
; CHECK-NEXT: br label [[LOOP_LATCH]]
; CHECK: cond.false:
; CHECK-NEXT: br label [[LOOP_LATCH]]
; CHECK: loop.latch:
; CHECK-NEXT: [[MERGE]] = phi i8 [ [[DIV]], [[COND_TRUE]] ], [ 0, [[COND_FALSE]] ]
; CHECK-NEXT: [[ADD]] = add i64 [[I]], 4
; CHECK-NEXT: br label [[LOOP_HEADER]]
; CHECK: for.end:
; CHECK-NEXT: [[MERGE1_LCSSA:%.*]] = phi i8 [ [[MERGE1]], [[LOOP_HEADER]] ]
; CHECK-NEXT: store i8 [[MERGE1_LCSSA]], i8* @glb, align 1
; CHECK-NEXT: ret void
;
entry:
br label %loop.header

loop.header:
%i = phi i64 [ 0, %entry ], [ %add, %loop.latch ]
%cmp = icmp ult i64 %i, 4
br i1 %cmp, label %loop.body, label %for.end

loop.body:
%div = sdiv i8 %var, 3
%cmp2 = icmp slt i8 %div, 0
br i1 %cmp2, label %cond.true, label %cond.false

cond.true:
br label %loop.latch

cond.false:
br label %loop.latch

loop.latch:
%merge = phi i8 [ %div, %cond.true ], [ 0, %cond.false ]
store i8 %merge, i8* @glb, align 1
%add = add i64 %i, 4
br label %loop.header

for.end:
ret void
}

!0 = !{!4, !4, i64 0}
!1 = !{!"omnipotent char", !2}
!2 = !{!"Simple C/C++ TBAA"}
Expand Down

0 comments on commit b42c054

Please sign in to comment.