Skip to content

Commit ded0d6f

Browse files
committed
[InstCombine] Add pre-commit tests. NFC.
1 parent ababa96 commit ded0d6f

File tree

1 file changed

+93
-0
lines changed
  • llvm/test/Transforms/InstCombine

1 file changed

+93
-0
lines changed

llvm/test/Transforms/InstCombine/not.ll

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,3 +769,96 @@ entry:
769769
%cmp = icmp sle i32 %select, %not.c
770770
ret i1 %cmp
771771
}
772+
773+
define i32 @test_sext(i32 %a, i32 %b){
774+
; CHECK-LABEL: @test_sext(
775+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], 0
776+
; CHECK-NEXT: [[SEXT:%.*]] = sext i1 [[CMP]] to i32
777+
; CHECK-NEXT: [[ADD:%.*]] = add i32 [[SEXT]], [[B:%.*]]
778+
; CHECK-NEXT: [[NOT:%.*]] = xor i32 [[ADD]], -1
779+
; CHECK-NEXT: ret i32 [[NOT]]
780+
;
781+
%cmp = icmp eq i32 %a, 0
782+
%sext = sext i1 %cmp to i32
783+
%add = add i32 %b, %sext
784+
%not = xor i32 %add, -1
785+
ret i32 %not
786+
}
787+
788+
define <2 x i32> @test_sext_vec(<2 x i32> %a, <2 x i32> %b){
789+
; CHECK-LABEL: @test_sext_vec(
790+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[A:%.*]], zeroinitializer
791+
; CHECK-NEXT: [[SEXT:%.*]] = sext <2 x i1> [[CMP]] to <2 x i32>
792+
; CHECK-NEXT: [[ADD:%.*]] = add <2 x i32> [[SEXT]], [[B:%.*]]
793+
; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i32> [[ADD]], <i32 -1, i32 -1>
794+
; CHECK-NEXT: ret <2 x i32> [[NOT]]
795+
;
796+
%cmp = icmp eq <2 x i32> %a, zeroinitializer
797+
%sext = sext <2 x i1> %cmp to <2 x i32>
798+
%add = add <2 x i32> %b, %sext
799+
%not = xor <2 x i32> %add, <i32 -1, i32 -1>
800+
ret <2 x i32> %not
801+
}
802+
803+
define i32 @test_zext_nneg(i32 %a, i32 %b){
804+
; CHECK-LABEL: @test_zext_nneg(
805+
; CHECK-NEXT: [[NOT:%.*]] = xor i32 [[B:%.*]], -1
806+
; CHECK-NEXT: ret i32 [[NOT]]
807+
;
808+
%cmp = icmp eq i32 %a, 0
809+
%sext = zext nneg i1 %cmp to i32
810+
%add = add i32 %b, %sext
811+
%not = xor i32 %add, -1
812+
ret i32 %not
813+
}
814+
815+
define i8 @test_trunc(i8 %a){
816+
; CHECK-LABEL: @test_trunc(
817+
; CHECK-NEXT: [[ZEXT:%.*]] = zext i8 [[A:%.*]] to i32
818+
; CHECK-NEXT: [[SUB:%.*]] = add nsw i32 [[ZEXT]], -1
819+
; CHECK-NEXT: [[SHR:%.*]] = ashr i32 [[SUB]], 31
820+
; CHECK-NEXT: [[CONV:%.*]] = trunc i32 [[SHR]] to i8
821+
; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[CONV]], -1
822+
; CHECK-NEXT: ret i8 [[NOT]]
823+
;
824+
%zext = zext i8 %a to i32
825+
%sub = add nsw i32 %zext, -1
826+
%shr = ashr i32 %sub, 31
827+
%conv = trunc i32 %shr to i8
828+
%not = xor i8 %conv, -1
829+
ret i8 %not
830+
}
831+
832+
define <2 x i8> @test_trunc_vec(<2 x i8> %a){
833+
; CHECK-LABEL: @test_trunc_vec(
834+
; CHECK-NEXT: [[ZEXT:%.*]] = zext <2 x i8> [[A:%.*]] to <2 x i32>
835+
; CHECK-NEXT: [[SUB:%.*]] = add nsw <2 x i32> [[ZEXT]], <i32 -1, i32 -1>
836+
; CHECK-NEXT: [[SHR:%.*]] = ashr <2 x i32> [[SUB]], <i32 31, i32 31>
837+
; CHECK-NEXT: [[CONV:%.*]] = trunc <2 x i32> [[SHR]] to <2 x i8>
838+
; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i8> [[CONV]], <i8 -1, i8 -1>
839+
; CHECK-NEXT: ret <2 x i8> [[NOT]]
840+
;
841+
%zext = zext <2 x i8> %a to <2 x i32>
842+
%sub = add nsw <2 x i32> %zext, <i32 -1, i32 -1>
843+
%shr = ashr <2 x i32> %sub, <i32 31, i32 31>
844+
%conv = trunc <2 x i32> %shr to <2 x i8>
845+
%not = xor <2 x i8> %conv, <i8 -1, i8 -1>
846+
ret <2 x i8> %not
847+
}
848+
849+
; Negative tests
850+
851+
define i32 @test_zext(i32 %a, i32 %b){
852+
; CHECK-LABEL: @test_zext(
853+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], 0
854+
; CHECK-NEXT: [[SEXT:%.*]] = zext i1 [[CMP]] to i32
855+
; CHECK-NEXT: [[ADD:%.*]] = add i32 [[SEXT]], [[B:%.*]]
856+
; CHECK-NEXT: [[NOT:%.*]] = xor i32 [[ADD]], -1
857+
; CHECK-NEXT: ret i32 [[NOT]]
858+
;
859+
%cmp = icmp eq i32 %a, 0
860+
%sext = zext i1 %cmp to i32
861+
%add = add i32 %b, %sext
862+
%not = xor i32 %add, -1
863+
ret i32 %not
864+
}

0 commit comments

Comments
 (0)