Skip to content

Commit 40fc765

Browse files
committed
Add negative test cases
1 parent 3eadf70 commit 40fc765

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed

llvm/test/Transforms/ConstraintElimination/and.ll

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,3 +740,71 @@ end:
740740
call void @use(i1 %t.3)
741741
ret void
742742
}
743+
744+
define void @test_decompose_bitwise_and_negative(i4 %x, i4 %y) {
745+
; CHECK-LABEL: @test_decompose_bitwise_and_negative(
746+
; CHECK-NEXT: entry:
747+
; CHECK-NEXT: [[AND_1:%.*]] = and i4 [[Y:%.*]], [[X:%.*]]
748+
; CHECK-NEXT: [[C_1:%.*]] = icmp slt i4 [[AND_1]], 0
749+
; CHECK-NEXT: br i1 [[C_1]], label [[THEN:%.*]], label [[END:%.*]]
750+
; CHECK: then:
751+
; CHECK-NEXT: ret void
752+
; CHECK: end:
753+
; CHECK-NEXT: [[C_2:%.*]] = icmp sgt i4 [[X]], 0
754+
; CHECK-NEXT: [[C_3:%.*]] = icmp sgt i4 [[Y]], 0
755+
; CHECK-NEXT: call void @use(i1 [[C_2]])
756+
; CHECK-NEXT: call void @use(i1 [[C_3]])
757+
; CHECK-NEXT: ret void
758+
;
759+
entry:
760+
%and.1 = and i4 %y, %x
761+
%c.1= icmp slt i4 %and.1, 0
762+
br i1 %c.1, label %then, label %end
763+
764+
then:
765+
; fact: %and.1 < 0
766+
ret void
767+
768+
end:
769+
; fact: %and.1 >= 0
770+
; %c.2, %c.3 should only be replaced in the bitwise OR case
771+
%c.2 = icmp sgt i4 %x, 0
772+
%c.3 = icmp sgt i4 %y, 0
773+
call void @use(i1 %c.2)
774+
call void @use(i1 %c.3)
775+
ret void
776+
}
777+
778+
define void @test_decompose_bitwise_and_negative_2(i4 %x, i4 %y) {
779+
; CHECK-LABEL: @test_decompose_bitwise_and_negative_2(
780+
; CHECK-NEXT: entry:
781+
; CHECK-NEXT: [[AND_1:%.*]] = and i4 [[X:%.*]], [[Y:%.*]]
782+
; CHECK-NEXT: [[C_1:%.*]] = icmp sgt i4 [[AND_1]], -1
783+
; CHECK-NEXT: br i1 [[C_1]], label [[THEN:%.*]], label [[END:%.*]]
784+
; CHECK: then:
785+
; CHECK-NEXT: [[C_2:%.*]] = icmp sgt i4 [[X]], 0
786+
; CHECK-NEXT: [[C_3:%.*]] = icmp sgt i4 [[Y]], 0
787+
; CHECK-NEXT: call void @use(i1 [[C_2]])
788+
; CHECK-NEXT: call void @use(i1 [[C_3]])
789+
; CHECK-NEXT: ret void
790+
; CHECK: end:
791+
; CHECK-NEXT: ret void
792+
;
793+
entry:
794+
%and.1 = and i4 %x, %y
795+
%c.1 = icmp sgt i4 %and.1, -1
796+
br i1 %c.1, label %then, label %end
797+
798+
then:
799+
; fact: %and.1 > -1
800+
; %c.1, %c.2 should only be replaced in the bitwise OR case
801+
%c.2 = icmp sgt i4 %x, 0
802+
%c.3 = icmp sgt i4 %y, 0
803+
call void @use(i1 %c.2)
804+
call void @use(i1 %c.3)
805+
ret void
806+
807+
end:
808+
; fact: %and.1 <= -1
809+
ret void
810+
}

llvm/test/Transforms/ConstraintElimination/or.ll

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,3 +943,71 @@ end:
943943
call void @use(i1 %t.4)
944944
ret void
945945
}
946+
947+
define void @test_decompose_bitwise_or_negative(i4 %x, i4 %y) {
948+
; CHECK-LABEL: @test_decompose_bitwise_or_negative(
949+
; CHECK-NEXT: entry:
950+
; CHECK-NEXT: [[OR_1:%.*]] = or i4 [[X:%.*]], [[Y:%.*]]
951+
; CHECK-NEXT: [[C_1:%.*]] = icmp sgt i4 [[OR_1]], -1
952+
; CHECK-NEXT: br i1 [[C_1]], label [[THEN:%.*]], label [[END:%.*]]
953+
; CHECK: then:
954+
; CHECK-NEXT: ret void
955+
; CHECK: end:
956+
; CHECK-NEXT: [[C_2:%.*]] = icmp slt i4 [[X]], 0
957+
; CHECK-NEXT: [[C_3:%.*]] = icmp slt i4 [[Y]], 0
958+
; CHECK-NEXT: call void @use(i1 [[C_2]])
959+
; CHECK-NEXT: call void @use(i1 [[C_3]])
960+
; CHECK-NEXT: ret void
961+
;
962+
entry:
963+
%or.1 = or i4 %x, %y
964+
%c.1 = icmp sgt i4 %or.1, -1
965+
br i1 %c.1, label %then, label %end
966+
967+
then:
968+
; fact: %or.1 > -1
969+
ret void
970+
971+
end:
972+
; fact: %or.1 <= -1
973+
; %c.2, %c.3 should only be replaced in the bitwise AND case
974+
%c.2 = icmp slt i4 %x, 0
975+
%c.3 = icmp slt i4 %y, 0
976+
call void @use(i1 %c.2)
977+
call void @use(i1 %c.3)
978+
ret void
979+
}
980+
981+
define void @test_decompose_bitwise_or_negative2(i4 %x, i4 %y) {
982+
; CHECK-LABEL: @test_decompose_bitwise_or_negative2(
983+
; CHECK-NEXT: entry:
984+
; CHECK-NEXT: [[OR_1:%.*]] = or i4 [[Y:%.*]], [[X:%.*]]
985+
; CHECK-NEXT: [[C_1:%.*]] = icmp slt i4 [[OR_1]], 0
986+
; CHECK-NEXT: br i1 [[C_1]], label [[THEN:%.*]], label [[END:%.*]]
987+
; CHECK: then:
988+
; CHECK-NEXT: [[C_2:%.*]] = icmp slt i4 [[X]], 0
989+
; CHECK-NEXT: [[C_3:%.*]] = icmp slt i4 [[Y]], 0
990+
; CHECK-NEXT: call void @use(i1 [[C_2]])
991+
; CHECK-NEXT: call void @use(i1 [[C_3]])
992+
; CHECK-NEXT: ret void
993+
; CHECK: end:
994+
; CHECK-NEXT: ret void
995+
;
996+
entry:
997+
%or.1 = or i4 %y, %x
998+
%c.1 = icmp slt i4 %or.1, 0
999+
br i1 %c.1, label %then, label %end
1000+
1001+
then:
1002+
; fact: %or.1 < 0
1003+
; %c.2, %c.3 should only be replaced in the bitwise AND case
1004+
%c.2 = icmp slt i4 %x, 0
1005+
%c.3 = icmp slt i4 %y, 0
1006+
call void @use(i1 %c.2)
1007+
call void @use(i1 %c.3)
1008+
ret void
1009+
1010+
end:
1011+
; fact: %or.1 >= 0
1012+
ret void
1013+
}

0 commit comments

Comments
 (0)