@@ -695,3 +695,75 @@ define i1 @test_missing_nusw(ptr %p, i32 %x, i32 %y) {
695
695
%cmp2 = icmp ugt ptr %gep.x1 , %gep.y
696
696
ret i1 %cmp2
697
697
}
698
+
699
+ define i1 @test_nuw (ptr %p , i64 %x , i64 %y ) {
700
+ ; CHECK-LABEL: @test_nuw(
701
+ ; CHECK-NEXT: [[CMP1:%.*]] = icmp ugt i64 [[X:%.*]], [[Y:%.*]]
702
+ ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP1]])
703
+ ; CHECK-NEXT: [[GEP_X:%.*]] = getelementptr nuw i8, ptr [[P:%.*]], i64 [[X]]
704
+ ; CHECK-NEXT: [[GEP_Y:%.*]] = getelementptr nuw i8, ptr [[P]], i64 [[Y]]
705
+ ; CHECK-NEXT: [[CMP2:%.*]] = icmp ugt ptr [[GEP_X]], [[GEP_Y]]
706
+ ; CHECK-NEXT: ret i1 [[CMP2]]
707
+ ;
708
+ %cmp1 = icmp ugt i64 %x , %y
709
+ call void @llvm.assume (i1 %cmp1 )
710
+ %gep.x = getelementptr nuw i8 , ptr %p , i64 %x
711
+ %gep.y = getelementptr nuw i8 , ptr %p , i64 %y
712
+ %cmp2 = icmp ugt ptr %gep.x , %gep.y
713
+ ret i1 %cmp2
714
+ }
715
+
716
+ define i1 @test_nuw_nested (ptr %p , i64 %x , i64 %y ) {
717
+ ; CHECK-LABEL: @test_nuw_nested(
718
+ ; CHECK-NEXT: [[CMP1:%.*]] = icmp ugt i64 [[X:%.*]], [[Y:%.*]]
719
+ ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP1]])
720
+ ; CHECK-NEXT: [[GEP_X:%.*]] = getelementptr nuw i8, ptr [[P:%.*]], i64 [[X]]
721
+ ; CHECK-NEXT: [[GEP_X1:%.*]] = getelementptr nuw i8, ptr [[GEP_X]], i64 1
722
+ ; CHECK-NEXT: [[GEP_Y:%.*]] = getelementptr nuw i8, ptr [[P]], i64 [[Y]]
723
+ ; CHECK-NEXT: [[CMP2:%.*]] = icmp ugt ptr [[GEP_X1]], [[GEP_Y]]
724
+ ; CHECK-NEXT: ret i1 [[CMP2]]
725
+ ;
726
+ %cmp1 = icmp ugt i64 %x , %y
727
+ call void @llvm.assume (i1 %cmp1 )
728
+ %gep.x = getelementptr nuw i8 , ptr %p , i64 %x
729
+ %gep.x1 = getelementptr nuw i8 , ptr %gep.x , i64 1
730
+ %gep.y = getelementptr nuw i8 , ptr %p , i64 %y
731
+ %cmp2 = icmp ugt ptr %gep.x1 , %gep.y
732
+ ret i1 %cmp2
733
+ }
734
+
735
+ define i1 @test_nuw_nested_missing_nuw (ptr %p , i64 %x , i64 %y ) {
736
+ ; CHECK-LABEL: @test_nuw_nested_missing_nuw(
737
+ ; CHECK-NEXT: [[CMP1:%.*]] = icmp ugt i64 [[X:%.*]], [[Y:%.*]]
738
+ ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP1]])
739
+ ; CHECK-NEXT: [[GEP_X:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 [[X]]
740
+ ; CHECK-NEXT: [[GEP_X1:%.*]] = getelementptr nuw i8, ptr [[GEP_X]], i64 1
741
+ ; CHECK-NEXT: [[GEP_Y:%.*]] = getelementptr nuw i8, ptr [[P]], i64 [[Y]]
742
+ ; CHECK-NEXT: [[CMP2:%.*]] = icmp ugt ptr [[GEP_X1]], [[GEP_Y]]
743
+ ; CHECK-NEXT: ret i1 [[CMP2]]
744
+ ;
745
+ %cmp1 = icmp ugt i64 %x , %y
746
+ call void @llvm.assume (i1 %cmp1 )
747
+ %gep.x = getelementptr i8 , ptr %p , i64 %x
748
+ %gep.x1 = getelementptr nuw i8 , ptr %gep.x , i64 1
749
+ %gep.y = getelementptr nuw i8 , ptr %p , i64 %y
750
+ %cmp2 = icmp ugt ptr %gep.x1 , %gep.y
751
+ ret i1 %cmp2
752
+ }
753
+
754
+ define i1 @test_nuw_incorrect_precondition (ptr %p , i64 %x , i64 %y ) {
755
+ ; CHECK-LABEL: @test_nuw_incorrect_precondition(
756
+ ; CHECK-NEXT: [[CMP1:%.*]] = icmp uge i64 [[X:%.*]], [[Y:%.*]]
757
+ ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP1]])
758
+ ; CHECK-NEXT: [[GEP_X:%.*]] = getelementptr nuw i8, ptr [[P:%.*]], i64 [[X]]
759
+ ; CHECK-NEXT: [[GEP_Y:%.*]] = getelementptr nuw i8, ptr [[P]], i64 [[Y]]
760
+ ; CHECK-NEXT: [[CMP2:%.*]] = icmp ugt ptr [[GEP_X]], [[GEP_Y]]
761
+ ; CHECK-NEXT: ret i1 [[CMP2]]
762
+ ;
763
+ %cmp1 = icmp uge i64 %x , %y
764
+ call void @llvm.assume (i1 %cmp1 )
765
+ %gep.x = getelementptr nuw i8 , ptr %p , i64 %x
766
+ %gep.y = getelementptr nuw i8 , ptr %p , i64 %y
767
+ %cmp2 = icmp ugt ptr %gep.x , %gep.y
768
+ ret i1 %cmp2
769
+ }
0 commit comments