Skip to content

Commit fff84d3

Browse files
committed
[LV] Add test which sinks a load a across an aliasing store.
1 parent f79f04a commit fff84d3

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed

llvm/test/Transforms/LoopVectorize/if-pred-stores.ll

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,3 +623,139 @@ for.inc:
623623
for.end:
624624
ret void
625625
}
626+
627+
define void @minimal_bit_widths_with_aliasing_store(i1 %c, i8* %ptr) {
628+
; UNROLL-LABEL: @minimal_bit_widths_with_aliasing_store(
629+
; UNROLL-NEXT: entry:
630+
; UNROLL-NEXT: br label [[FOR_BODY:%.*]]
631+
; UNROLL: for.body:
632+
; UNROLL-NEXT: [[TMP0:%.*]] = phi i64 [ [[TMP6:%.*]], [[FOR_INC:%.*]] ], [ 0, [[ENTRY:%.*]] ]
633+
; UNROLL-NEXT: [[TMP1:%.*]] = phi i64 [ [[TMP7:%.*]], [[FOR_INC]] ], [ 0, [[ENTRY]] ]
634+
; UNROLL-NEXT: [[TMP2:%.*]] = getelementptr i8, i8* [[PTR:%.*]], i64 [[TMP0]]
635+
; UNROLL-NEXT: [[TMP3:%.*]] = load i8, i8* [[TMP2]], align 1
636+
; UNROLL-NEXT: store i8 0, i8* [[TMP2]], align 1
637+
; UNROLL-NEXT: br i1 [[C:%.*]], label [[IF_THEN:%.*]], label [[FOR_INC]]
638+
; UNROLL: if.then:
639+
; UNROLL-NEXT: [[TMP4:%.*]] = zext i8 [[TMP3]] to i32
640+
; UNROLL-NEXT: [[TMP5:%.*]] = trunc i32 [[TMP4]] to i8
641+
; UNROLL-NEXT: store i8 [[TMP5]], i8* [[TMP2]], align 1
642+
; UNROLL-NEXT: br label [[FOR_INC]]
643+
; UNROLL: for.inc:
644+
; UNROLL-NEXT: [[TMP6]] = add nuw nsw i64 [[TMP0]], 1
645+
; UNROLL-NEXT: [[TMP7]] = add i64 [[TMP1]], -1
646+
; UNROLL-NEXT: [[TMP8:%.*]] = icmp eq i64 [[TMP7]], 0
647+
; UNROLL-NEXT: br i1 [[TMP8]], label [[FOR_END:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP6:![0-9]+]]
648+
; UNROLL: for.end:
649+
; UNROLL-NEXT: ret void
650+
;
651+
; UNROLL-NOSIMPLIFY-LABEL: @minimal_bit_widths_with_aliasing_store(
652+
; UNROLL-NOSIMPLIFY-NEXT: entry:
653+
; UNROLL-NOSIMPLIFY-NEXT: br i1 true, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
654+
; UNROLL-NOSIMPLIFY: vector.ph:
655+
; UNROLL-NOSIMPLIFY-NEXT: br label [[VECTOR_BODY:%.*]]
656+
; UNROLL-NOSIMPLIFY: vector.body:
657+
; UNROLL-NOSIMPLIFY-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[PRED_STORE_CONTINUE6:%.*]] ]
658+
; UNROLL-NOSIMPLIFY-NEXT: [[INDUCTION:%.*]] = add i64 [[INDEX]], 0
659+
; UNROLL-NOSIMPLIFY-NEXT: [[INDUCTION2:%.*]] = add i64 [[INDEX]], 1
660+
; UNROLL-NOSIMPLIFY-NEXT: [[OFFSET_IDX:%.*]] = sub i64 0, [[INDEX]]
661+
; UNROLL-NOSIMPLIFY-NEXT: [[INDUCTION3:%.*]] = add i64 [[OFFSET_IDX]], 0
662+
; UNROLL-NOSIMPLIFY-NEXT: [[INDUCTION4:%.*]] = add i64 [[OFFSET_IDX]], -1
663+
; UNROLL-NOSIMPLIFY-NEXT: [[TMP0:%.*]] = getelementptr i8, i8* [[PTR:%.*]], i64 [[INDUCTION]]
664+
; UNROLL-NOSIMPLIFY-NEXT: [[TMP1:%.*]] = getelementptr i8, i8* [[PTR]], i64 [[INDUCTION2]]
665+
; UNROLL-NOSIMPLIFY-NEXT: store i8 0, i8* [[TMP0]], align 1
666+
; UNROLL-NOSIMPLIFY-NEXT: store i8 0, i8* [[TMP1]], align 1
667+
; UNROLL-NOSIMPLIFY-NEXT: br i1 [[C:%.*]], label [[PRED_STORE_IF:%.*]], label [[PRED_STORE_CONTINUE:%.*]]
668+
; UNROLL-NOSIMPLIFY: pred.store.if:
669+
; UNROLL-NOSIMPLIFY-NEXT: [[TMP2:%.*]] = load i8, i8* [[TMP0]], align 1
670+
; UNROLL-NOSIMPLIFY-NEXT: [[TMP3:%.*]] = zext i8 [[TMP2]] to i32
671+
; UNROLL-NOSIMPLIFY-NEXT: [[TMP4:%.*]] = trunc i32 [[TMP3]] to i8
672+
; UNROLL-NOSIMPLIFY-NEXT: store i8 [[TMP4]], i8* [[TMP0]], align 1
673+
; UNROLL-NOSIMPLIFY-NEXT: br label [[PRED_STORE_CONTINUE]]
674+
; UNROLL-NOSIMPLIFY: pred.store.continue:
675+
; UNROLL-NOSIMPLIFY-NEXT: br i1 [[C]], label [[PRED_STORE_IF5:%.*]], label [[PRED_STORE_CONTINUE6]]
676+
; UNROLL-NOSIMPLIFY: pred.store.if5:
677+
; UNROLL-NOSIMPLIFY-NEXT: [[TMP5:%.*]] = load i8, i8* [[TMP1]], align 1
678+
; UNROLL-NOSIMPLIFY-NEXT: [[TMP6:%.*]] = zext i8 [[TMP5]] to i32
679+
; UNROLL-NOSIMPLIFY-NEXT: [[TMP7:%.*]] = trunc i32 [[TMP6]] to i8
680+
; UNROLL-NOSIMPLIFY-NEXT: store i8 [[TMP7]], i8* [[TMP1]], align 1
681+
; UNROLL-NOSIMPLIFY-NEXT: br label [[PRED_STORE_CONTINUE6]]
682+
; UNROLL-NOSIMPLIFY: pred.store.continue6:
683+
; UNROLL-NOSIMPLIFY-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], 2
684+
; UNROLL-NOSIMPLIFY-NEXT: [[TMP8:%.*]] = icmp eq i64 [[INDEX_NEXT]], 0
685+
; UNROLL-NOSIMPLIFY-NEXT: br i1 [[TMP8]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP7:![0-9]+]]
686+
; UNROLL-NOSIMPLIFY: middle.block:
687+
; UNROLL-NOSIMPLIFY-NEXT: [[CMP_N:%.*]] = icmp eq i64 0, 0
688+
; UNROLL-NOSIMPLIFY-NEXT: br i1 [[CMP_N]], label [[FOR_END:%.*]], label [[SCALAR_PH]]
689+
; UNROLL-NOSIMPLIFY: scalar.ph:
690+
; UNROLL-NOSIMPLIFY-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 0, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
691+
; UNROLL-NOSIMPLIFY-NEXT: [[BC_RESUME_VAL1:%.*]] = phi i64 [ 0, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ]
692+
; UNROLL-NOSIMPLIFY-NEXT: br label [[FOR_BODY:%.*]]
693+
; UNROLL-NOSIMPLIFY: for.body:
694+
; UNROLL-NOSIMPLIFY-NEXT: [[TMP0:%.*]] = phi i64 [ [[TMP6:%.*]], [[FOR_INC:%.*]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
695+
; UNROLL-NOSIMPLIFY-NEXT: [[TMP1:%.*]] = phi i64 [ [[TMP7:%.*]], [[FOR_INC]] ], [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ]
696+
; UNROLL-NOSIMPLIFY-NEXT: [[TMP2:%.*]] = getelementptr i8, i8* [[PTR]], i64 [[TMP0]]
697+
; UNROLL-NOSIMPLIFY-NEXT: [[TMP3:%.*]] = load i8, i8* [[TMP2]], align 1
698+
; UNROLL-NOSIMPLIFY-NEXT: store i8 0, i8* [[TMP2]], align 1
699+
; UNROLL-NOSIMPLIFY-NEXT: br i1 [[C]], label [[IF_THEN:%.*]], label [[FOR_INC]]
700+
; UNROLL-NOSIMPLIFY: if.then:
701+
; UNROLL-NOSIMPLIFY-NEXT: [[TMP4:%.*]] = zext i8 [[TMP3]] to i32
702+
; UNROLL-NOSIMPLIFY-NEXT: [[TMP5:%.*]] = trunc i32 [[TMP4]] to i8
703+
; UNROLL-NOSIMPLIFY-NEXT: store i8 [[TMP5]], i8* [[TMP2]], align 1
704+
; UNROLL-NOSIMPLIFY-NEXT: br label [[FOR_INC]]
705+
; UNROLL-NOSIMPLIFY: for.inc:
706+
; UNROLL-NOSIMPLIFY-NEXT: [[TMP6]] = add nuw nsw i64 [[TMP0]], 1
707+
; UNROLL-NOSIMPLIFY-NEXT: [[TMP7]] = add i64 [[TMP1]], -1
708+
; UNROLL-NOSIMPLIFY-NEXT: [[TMP8:%.*]] = icmp eq i64 [[TMP7]], 0
709+
; UNROLL-NOSIMPLIFY-NEXT: br i1 [[TMP8]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP8:![0-9]+]]
710+
; UNROLL-NOSIMPLIFY: for.end:
711+
; UNROLL-NOSIMPLIFY-NEXT: ret void
712+
;
713+
; VEC-LABEL: @minimal_bit_widths_with_aliasing_store(
714+
; VEC-NEXT: entry:
715+
; VEC-NEXT: br label [[FOR_BODY:%.*]]
716+
; VEC: for.body:
717+
; VEC-NEXT: [[TMP0:%.*]] = phi i64 [ [[TMP6:%.*]], [[FOR_INC:%.*]] ], [ 0, [[ENTRY:%.*]] ]
718+
; VEC-NEXT: [[TMP1:%.*]] = phi i64 [ [[TMP7:%.*]], [[FOR_INC]] ], [ 0, [[ENTRY]] ]
719+
; VEC-NEXT: [[TMP2:%.*]] = getelementptr i8, i8* [[PTR:%.*]], i64 [[TMP0]]
720+
; VEC-NEXT: [[TMP3:%.*]] = load i8, i8* [[TMP2]], align 1
721+
; VEC-NEXT: store i8 0, i8* [[TMP2]], align 1
722+
; VEC-NEXT: br i1 [[C:%.*]], label [[IF_THEN:%.*]], label [[FOR_INC]]
723+
; VEC: if.then:
724+
; VEC-NEXT: [[TMP4:%.*]] = zext i8 [[TMP3]] to i32
725+
; VEC-NEXT: [[TMP5:%.*]] = trunc i32 [[TMP4]] to i8
726+
; VEC-NEXT: store i8 [[TMP5]], i8* [[TMP2]], align 1
727+
; VEC-NEXT: br label [[FOR_INC]]
728+
; VEC: for.inc:
729+
; VEC-NEXT: [[TMP6]] = add nuw nsw i64 [[TMP0]], 1
730+
; VEC-NEXT: [[TMP7]] = add i64 [[TMP1]], -1
731+
; VEC-NEXT: [[TMP8:%.*]] = icmp eq i64 [[TMP7]], 0
732+
; VEC-NEXT: br i1 [[TMP8]], label [[FOR_END:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP7:![0-9]+]]
733+
; VEC: for.end:
734+
; VEC-NEXT: ret void
735+
;
736+
entry:
737+
br label %for.body
738+
739+
for.body:
740+
%tmp0 = phi i64 [ %tmp6, %for.inc ], [ 0, %entry ]
741+
%tmp1 = phi i64 [ %tmp7, %for.inc ], [ 0, %entry ]
742+
%tmp2 = getelementptr i8, i8* %ptr, i64 %tmp0
743+
%tmp3 = load i8, i8* %tmp2, align 1
744+
store i8 0, i8* %tmp2
745+
br i1 %c, label %if.then, label %for.inc
746+
747+
if.then:
748+
%tmp4 = zext i8 %tmp3 to i32
749+
%tmp5 = trunc i32 %tmp4 to i8
750+
store i8 %tmp5, i8* %tmp2, align 1
751+
br label %for.inc
752+
753+
for.inc:
754+
%tmp6 = add nuw nsw i64 %tmp0, 1
755+
%tmp7 = add i64 %tmp1, -1
756+
%tmp8 = icmp eq i64 %tmp7, 0
757+
br i1 %tmp8, label %for.end, label %for.body
758+
759+
for.end:
760+
ret void
761+
}

0 commit comments

Comments
 (0)