Skip to content

Commit e7bc7db

Browse files
committed
[InstCombine] Pre-commit tests (NFC)
1 parent b214ca8 commit e7bc7db

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

llvm/test/Transforms/InstCombine/addsub-constant-folding.ll

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,3 +750,112 @@ define i8 @sub_from_constant_extra_use(i8 %x, i8 %y) {
750750
%r = add i8 %sub, %y
751751
ret i8 %r
752752
}
753+
754+
define i32 @sub_plus_mul(i32 %x, i32 %y) {
755+
; CHECK-LABEL: @sub_plus_mul(
756+
; CHECK-NEXT: [[A:%.*]] = sub i32 [[X:%.*]], [[Y:%.*]]
757+
; CHECK-NEXT: [[B:%.*]] = mul i32 [[Y]], 10
758+
; CHECK-NEXT: [[C:%.*]] = add i32 [[A]], [[B]]
759+
; CHECK-NEXT: ret i32 [[C]]
760+
;
761+
%a = sub i32 %x, %y
762+
%b = mul i32 %y, 10
763+
%c = add i32 %a, %b
764+
ret i32 %c
765+
}
766+
767+
define i32 @sub_plus_mul_2(i32 %x, i32 %y) {
768+
; CHECK-LABEL: @sub_plus_mul_2(
769+
; CHECK-NEXT: [[A:%.*]] = sub i32 [[X:%.*]], [[Y:%.*]]
770+
; CHECK-NEXT: [[B:%.*]] = mul i32 [[Y]], -10
771+
; CHECK-NEXT: [[C:%.*]] = add i32 [[A]], [[B]]
772+
; CHECK-NEXT: ret i32 [[C]]
773+
;
774+
%a = sub i32 %x, %y
775+
%b = mul i32 %y, -10
776+
%c = add i32 %a, %b
777+
ret i32 %c
778+
}
779+
780+
define i32 @sub_plus_mul3(i32 %x, i32 %y) {
781+
; CHECK-LABEL: @sub_plus_mul3(
782+
; CHECK-NEXT: [[A:%.*]] = mul i32 [[Y:%.*]], 10
783+
; CHECK-NEXT: [[B:%.*]] = sub i32 [[X:%.*]], [[Y]]
784+
; CHECK-NEXT: [[C:%.*]] = add i32 [[B]], [[A]]
785+
; CHECK-NEXT: ret i32 [[C]]
786+
;
787+
%a = mul i32 %y, 10
788+
%b = sub i32 %x, %y
789+
%c = add i32 %b, %a
790+
ret i32 %c
791+
}
792+
793+
define i32 @sub_plus_mul4(i32 %x, i32 %y) {
794+
; CHECK-LABEL: @sub_plus_mul4(
795+
; CHECK-NEXT: [[A:%.*]] = mul i32 [[Y:%.*]], -10
796+
; CHECK-NEXT: [[B:%.*]] = sub i32 [[X:%.*]], [[Y]]
797+
; CHECK-NEXT: [[C:%.*]] = add i32 [[B]], [[A]]
798+
; CHECK-NEXT: ret i32 [[C]]
799+
;
800+
%a = mul i32 %y, -10
801+
%b = sub i32 %x, %y
802+
%c = add i32 %b, %a
803+
ret i32 %c
804+
}
805+
806+
define <2 x i8> @sub_plus_mul_splat(<2 x i8> %x, <2 x i8> %y) {
807+
; CHECK-LABEL: @sub_plus_mul_splat(
808+
; CHECK-NEXT: [[A:%.*]] = sub <2 x i8> [[X:%.*]], [[Y:%.*]]
809+
; CHECK-NEXT: [[B:%.*]] = mul <2 x i8> [[Y]], splat (i8 7)
810+
; CHECK-NEXT: [[C:%.*]] = add <2 x i8> [[A]], [[B]]
811+
; CHECK-NEXT: ret <2 x i8> [[C]]
812+
;
813+
%a = sub <2 x i8> %x, %y
814+
%b = mul <2 x i8> %y, splat(i8 7)
815+
%c = add <2 x i8> %a, %b
816+
ret <2 x i8> %c
817+
}
818+
819+
;; <- Negative Tests ->
820+
821+
;; mul does not work if it is a powerof2, because it results in worse codegen
822+
define i32 @neg_sub_plus_mul_pow2(i32 %x, i32 %y) {
823+
; CHECK-LABEL: @neg_sub_plus_mul_pow2(
824+
; CHECK-NEXT: [[A:%.*]] = sub i32 [[X:%.*]], [[Y:%.*]]
825+
; CHECK-NEXT: [[B:%.*]] = shl i32 [[Y]], 3
826+
; CHECK-NEXT: [[C:%.*]] = add i32 [[A]], [[B]]
827+
; CHECK-NEXT: ret i32 [[C]]
828+
;
829+
%a = sub i32 %x, %y
830+
%b = mul i32 %y, 8
831+
%c = add i32 %a, %b
832+
ret i32 %c
833+
}
834+
835+
define <2 x i8> @sub_plus_mul_splat_shl(<2 x i8> %x, <2 x i8> %y) {
836+
; CHECK-LABEL: @sub_plus_mul_splat_shl(
837+
; CHECK-NEXT: [[A:%.*]] = sub <2 x i8> [[X:%.*]], [[Y:%.*]]
838+
; CHECK-NEXT: [[B:%.*]] = shl <2 x i8> [[Y]], splat (i8 3)
839+
; CHECK-NEXT: [[C:%.*]] = add <2 x i8> [[A]], [[B]]
840+
; CHECK-NEXT: ret <2 x i8> [[C]]
841+
;
842+
%a = sub <2 x i8> %x, %y
843+
%b = mul <2 x i8> %y, splat(i8 8)
844+
%c = add <2 x i8> %a, %b
845+
ret <2 x i8> %c
846+
}
847+
848+
define i32 @neg_sub_plus_mul_multiuse(i32 %x, i32 %y) {
849+
; CHECK-LABEL: @neg_sub_plus_mul_multiuse(
850+
; CHECK-NEXT: [[A:%.*]] = sub i32 [[X:%.*]], [[Y:%.*]]
851+
; CHECK-NEXT: [[B:%.*]] = mul i32 [[Y]], 7
852+
; CHECK-NEXT: call void @use(i32 [[B]])
853+
; CHECK-NEXT: [[C:%.*]] = add i32 [[A]], [[B]]
854+
; CHECK-NEXT: ret i32 [[C]]
855+
;
856+
%a = sub i32 %x, %y
857+
%b = mul i32 %y, 7
858+
call void @use(i32 %b)
859+
%c = add i32 %a, %b
860+
ret i32 %c
861+
}

0 commit comments

Comments
 (0)