@@ -566,3 +566,78 @@ define i1 @gep_i16_sub_1_uge_inbounds_var_idx(ptr %dst, i64 %off) {
566
566
%res.2 = xor i1 %res.1 , %cmp.sub.3
567
567
ret i1 %res.2
568
568
}
569
+
570
+ define i1 @gep_i32_two_indices_known_lt_and_positive (ptr %a , i8 %idx.1 , i8 %idx.2 ) {
571
+ ; CHECK-LABEL: @gep_i32_two_indices_known_lt_and_positive(
572
+ ; CHECK-NEXT: [[LT:%.*]] = icmp ult i8 [[IDX_1:%.*]], [[IDX_2:%.*]]
573
+ ; CHECK-NEXT: call void @llvm.assume(i1 [[LT]])
574
+ ; CHECK-NEXT: [[IDX_1_POS:%.*]] = icmp sge i8 [[IDX_1]], 0
575
+ ; CHECK-NEXT: [[IDX_2_POS:%.*]] = icmp sge i8 [[IDX_2]], 0
576
+ ; CHECK-NEXT: call void @llvm.assume(i1 [[IDX_1_POS]])
577
+ ; CHECK-NEXT: call void @llvm.assume(i1 [[IDX_2_POS]])
578
+ ; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i8 [[IDX_1]]
579
+ ; CHECK-NEXT: [[GEP_2:%.*]] = getelementptr inbounds i32, ptr [[GEP_1]], i8 -3
580
+ ; CHECK-NEXT: [[GEP_3:%.*]] = getelementptr inbounds i32, ptr [[A]], i8 [[IDX_2]]
581
+ ; CHECK-NEXT: [[GEP_4:%.*]] = getelementptr inbounds i32, ptr [[GEP_3]], i8 -3
582
+ ; CHECK-NEXT: [[C:%.*]] = icmp ult ptr [[GEP_2]], [[GEP_4]]
583
+ ; CHECK-NEXT: ret i1 [[C]]
584
+ ;
585
+ %lt = icmp ult i8 %idx.1 , %idx.2
586
+ call void @llvm.assume (i1 %lt )
587
+ %idx.1.pos = icmp sge i8 %idx.1 , 0
588
+ %idx.2.pos = icmp sge i8 %idx.2 , 0
589
+ call void @llvm.assume (i1 %idx.1.pos )
590
+ call void @llvm.assume (i1 %idx.2.pos )
591
+ %gep.1 = getelementptr inbounds i32 , ptr %a , i8 %idx.1
592
+ %gep.2 = getelementptr inbounds i32 , ptr %gep.1 , i8 -3
593
+ %gep.3 = getelementptr inbounds i32 , ptr %a , i8 %idx.2
594
+ %gep.4 = getelementptr inbounds i32 , ptr %gep.3 , i8 -3
595
+ %c = icmp ult ptr %gep.2 , %gep.4
596
+ ret i1 %c
597
+ }
598
+
599
+ define i1 @gep_i32_two_indices_known_lt_and_not_known_positive (ptr %a , i8 %idx.1 , i8 %idx.2 ) {
600
+ ; CHECK-LABEL: @gep_i32_two_indices_known_lt_and_not_known_positive(
601
+ ; CHECK-NEXT: [[LT:%.*]] = icmp ult i8 [[IDX_1:%.*]], [[IDX_2:%.*]]
602
+ ; CHECK-NEXT: call void @llvm.assume(i1 [[LT]])
603
+ ; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i8 [[IDX_1]]
604
+ ; CHECK-NEXT: [[GEP_2:%.*]] = getelementptr inbounds i32, ptr [[GEP_1]], i8 -3
605
+ ; CHECK-NEXT: [[GEP_3:%.*]] = getelementptr inbounds i32, ptr [[A]], i8 [[IDX_2]]
606
+ ; CHECK-NEXT: [[GEP_4:%.*]] = getelementptr inbounds i32, ptr [[GEP_3]], i8 -3
607
+ ; CHECK-NEXT: [[C:%.*]] = icmp ult ptr [[GEP_2]], [[GEP_4]]
608
+ ; CHECK-NEXT: ret i1 [[C]]
609
+ ;
610
+ %lt = icmp ult i8 %idx.1 , %idx.2
611
+ call void @llvm.assume (i1 %lt )
612
+ %gep.1 = getelementptr inbounds i32 , ptr %a , i8 %idx.1
613
+ %gep.2 = getelementptr inbounds i32 , ptr %gep.1 , i8 -3
614
+ %gep.3 = getelementptr inbounds i32 , ptr %a , i8 %idx.2
615
+ %gep.4 = getelementptr inbounds i32 , ptr %gep.3 , i8 -3
616
+ %c = icmp ult ptr %gep.2 , %gep.4
617
+ ret i1 %c
618
+ }
619
+
620
+ define i1 @gep_i32_two_indices_known_positive_but_not_lt (ptr %a , i8 %idx.1 , i8 %idx.2 ) {
621
+ ; CHECK-LABEL: @gep_i32_two_indices_known_positive_but_not_lt(
622
+ ; CHECK-NEXT: [[IDX_1_POS:%.*]] = icmp sge i8 [[IDX_1:%.*]], 0
623
+ ; CHECK-NEXT: [[IDX_2_POS:%.*]] = icmp sge i8 [[IDX_2:%.*]], 0
624
+ ; CHECK-NEXT: call void @llvm.assume(i1 [[IDX_1_POS]])
625
+ ; CHECK-NEXT: call void @llvm.assume(i1 [[IDX_2_POS]])
626
+ ; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i8 [[IDX_1]]
627
+ ; CHECK-NEXT: [[GEP_2:%.*]] = getelementptr inbounds i32, ptr [[GEP_1]], i8 -3
628
+ ; CHECK-NEXT: [[GEP_3:%.*]] = getelementptr inbounds i32, ptr [[A]], i8 [[IDX_2]]
629
+ ; CHECK-NEXT: [[GEP_4:%.*]] = getelementptr inbounds i32, ptr [[GEP_3]], i8 -3
630
+ ; CHECK-NEXT: [[C:%.*]] = icmp ult ptr [[GEP_2]], [[GEP_4]]
631
+ ; CHECK-NEXT: ret i1 [[C]]
632
+ ;
633
+ %idx.1.pos = icmp sge i8 %idx.1 , 0
634
+ %idx.2.pos = icmp sge i8 %idx.2 , 0
635
+ call void @llvm.assume (i1 %idx.1.pos )
636
+ call void @llvm.assume (i1 %idx.2.pos )
637
+ %gep.1 = getelementptr inbounds i32 , ptr %a , i8 %idx.1
638
+ %gep.2 = getelementptr inbounds i32 , ptr %gep.1 , i8 -3
639
+ %gep.3 = getelementptr inbounds i32 , ptr %a , i8 %idx.2
640
+ %gep.4 = getelementptr inbounds i32 , ptr %gep.3 , i8 -3
641
+ %c = icmp ult ptr %gep.2 , %gep.4
642
+ ret i1 %c
643
+ }
0 commit comments