[InstCombine] [NFC] Tests for select with binop fold

llvm-svn: 338727
This commit is contained in:
David Bolvansky 2018-08-02 14:59:23 +00:00
parent 300d363dfd
commit 67647bcfbe
1 changed files with 196 additions and 66 deletions

View File

@ -137,6 +137,99 @@ define i32 @select_xor_inv_icmp2(i32 %x, i32 %y, i32 %z) {
ret i32 %C
}
; TODO: Support for FP opcodes
define float @select_fadd_icmp(float %x, float %y, float %z) {
; CHECK-LABEL: @select_fadd_icmp(
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], -0.000000e+00
; CHECK-NEXT: [[B:%.*]] = fadd float [[X]], [[Z:%.*]]
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
; CHECK-NEXT: ret float [[C]]
;
%A = fcmp oeq float %x, -0.0
%B = fadd float %x, %z
%C = select i1 %A, float %B, float %y
ret float %C
}
define float @select_fadd_icmp2(float %x, float %y, float %z) {
; CHECK-LABEL: @select_fadd_icmp2(
; CHECK-NEXT: [[A:%.*]] = fcmp ueq float [[X:%.*]], -0.000000e+00
; CHECK-NEXT: [[B:%.*]] = fadd float [[X]], [[Z:%.*]]
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
; CHECK-NEXT: ret float [[C]]
;
%A = fcmp ueq float %x, -0.0
%B = fadd float %x, %z
%C = select i1 %A, float %B, float %y
ret float %C
}
define float @select_fmul_icmp(float %x, float %y, float %z) {
; CHECK-LABEL: @select_fmul_icmp(
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], 1.000000e+00
; CHECK-NEXT: [[B:%.*]] = fmul float [[X]], [[Z:%.*]]
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
; CHECK-NEXT: ret float [[C]]
;
%A = fcmp oeq float %x, 1.0
%B = fmul float %x, %z
%C = select i1 %A, float %B, float %y
ret float %C
}
; TODO: Support for non-commutative opcodes
define i32 @select_sub_icmp(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @select_sub_icmp(
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], 0
; CHECK-NEXT: [[B:%.*]] = sub i32 [[X]], [[Z:%.*]]
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 [[Y:%.*]]
; CHECK-NEXT: ret i32 [[C]]
;
%A = icmp eq i32 %x, 0
%B = sub i32 %x, %z
%C = select i1 %A, i32 %B, i32 %y
ret i32 %C
}
define i32 @select_shl_icmp(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @select_shl_icmp(
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], 0
; CHECK-NEXT: [[B:%.*]] = shl i32 [[X]], [[Z:%.*]]
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 [[Y:%.*]]
; CHECK-NEXT: ret i32 [[C]]
;
%A = icmp eq i32 %x, 0
%B = shl i32 %x, %z
%C = select i1 %A, i32 %B, i32 %y
ret i32 %C
}
define i32 @select_lshr_icmp(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @select_lshr_icmp(
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], 0
; CHECK-NEXT: [[B:%.*]] = lshr i32 [[X]], [[Z:%.*]]
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 [[Y:%.*]]
; CHECK-NEXT: ret i32 [[C]]
;
%A = icmp eq i32 %x, 0
%B = lshr i32 %x, %z
%C = select i1 %A, i32 %B, i32 %y
ret i32 %C
}
define i32 @select_ashr_icmp(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @select_ashr_icmp(
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], 0
; CHECK-NEXT: [[B:%.*]] = ashr i32 [[X]], [[Z:%.*]]
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 [[Y:%.*]]
; CHECK-NEXT: ret i32 [[C]]
;
%A = icmp eq i32 %x, 0
%B = ashr i32 %x, %z
%C = select i1 %A, i32 %B, i32 %y
ret i32 %C
}
; Negative tests
define i32 @select_xor_icmp_bad_1(i32 %x, i32 %y, i32 %z, i32 %k) {
; CHECK-LABEL: @select_xor_icmp_bad_1(
@ -295,97 +388,134 @@ define i32 @select_or_icmp_bad(i32 %x, i32 %y, i32 %z) {
ret i32 %C
}
; TODO: Support for non-commutative opcodes
define i32 @select_sub_icmp(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @select_sub_icmp(
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], 0
; CHECK-NEXT: [[B:%.*]] = sub i32 [[X]], [[Z:%.*]]
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 [[Y:%.*]]
; CHECK-NEXT: ret i32 [[C]]
;
%A = icmp eq i32 %x, 0
%B = sub i32 %x, %z
%C = select i1 %A, i32 %B, i32 %y
ret i32 %C
}
define i32 @select_shl_icmp(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @select_shl_icmp(
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], 0
; CHECK-NEXT: [[B:%.*]] = shl i32 [[X]], [[Z:%.*]]
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 [[Y:%.*]]
; CHECK-NEXT: ret i32 [[C]]
;
%A = icmp eq i32 %x, 0
%B = shl i32 %x, %z
%C = select i1 %A, i32 %B, i32 %y
ret i32 %C
}
define i32 @select_lshr_icmp(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @select_lshr_icmp(
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], 0
; CHECK-NEXT: [[B:%.*]] = lshr i32 [[X]], [[Z:%.*]]
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 [[Y:%.*]]
; CHECK-NEXT: ret i32 [[C]]
;
%A = icmp eq i32 %x, 0
%B = lshr i32 %x, %z
%C = select i1 %A, i32 %B, i32 %y
ret i32 %C
}
define i32 @select_ashr_icmp(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @select_ashr_icmp(
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], 0
; CHECK-NEXT: [[B:%.*]] = ashr i32 [[X]], [[Z:%.*]]
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 [[Y:%.*]]
; CHECK-NEXT: ret i32 [[C]]
;
%A = icmp eq i32 %x, 0
%B = ashr i32 %x, %z
%C = select i1 %A, i32 %B, i32 %y
ret i32 %C
}
; TODO: Support for FP opcodes
define float @select_fadd_icmp(float %x, float %y, float %z) {
; CHECK-LABEL: @select_fadd_icmp(
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], -0.000000e+00
define float @select_fadd_icmp_bad(float %x, float %y, float %z) {
; CHECK-LABEL: @select_fadd_icmp_bad(
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], -1.000000e+00
; CHECK-NEXT: [[B:%.*]] = fadd float [[X]], [[Z:%.*]]
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
; CHECK-NEXT: ret float [[C]]
;
%A = fcmp oeq float %x, -0.0
%A = fcmp oeq float %x, -1.0
%B = fadd float %x, %z
%C = select i1 %A, float %B, float %y
ret float %C
}
define float @select_fadd_icmp2(float %x, float %y, float %z) {
; CHECK-LABEL: @select_fadd_icmp2(
; CHECK-NEXT: [[A:%.*]] = fcmp ueq float [[X:%.*]], -0.000000e+00
define float @select_fadd_icmp_bad_2(float %x, float %y, float %z) {
; CHECK-LABEL: @select_fadd_icmp_bad_2(
; CHECK-NEXT: [[A:%.*]] = fcmp ueq float [[X:%.*]], -1.000000e+00
; CHECK-NEXT: [[B:%.*]] = fadd float [[X]], [[Z:%.*]]
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
; CHECK-NEXT: ret float [[C]]
;
%A = fcmp ueq float %x, -0.0
%A = fcmp ueq float %x, -1.0
%B = fadd float %x, %z
%C = select i1 %A, float %B, float %y
ret float %C
}
define float @select_fmul_icmp(float %x, float %y, float %z) {
; CHECK-LABEL: @select_fmul_icmp(
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], 1.000000e+00
define float @select_fmul_icmp_bad(float %x, float %y, float %z) {
; CHECK-LABEL: @select_fmul_icmp_bad(
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], 3.000000e+00
; CHECK-NEXT: [[B:%.*]] = fmul float [[X]], [[Z:%.*]]
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
; CHECK-NEXT: ret float [[C]]
;
%A = fcmp oeq float %x, 1.0
%A = fcmp oeq float %x, 3.0
%B = fmul float %x, %z
%C = select i1 %A, float %B, float %y
ret float %C
}
define float @select_fdiv_icmp_bad(float %x, float %y, float %z) {
; CHECK-LABEL: @select_fdiv_icmp_bad(
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], 3.000000e+00
; CHECK-NEXT: [[B:%.*]] = fdiv float [[X]], [[Z:%.*]]
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
; CHECK-NEXT: ret float [[C]]
;
%A = fcmp oeq float %x, 3.0
%B = fdiv float %x, %z
%C = select i1 %A, float %B, float %y
ret float %C
}
define float @select_fsub_icmp_bad(float %x, float %y, float %z) {
; CHECK-LABEL: @select_fsub_icmp_bad(
; CHECK-NEXT: [[A:%.*]] = fcmp oeq float [[X:%.*]], 1.000000e+00
; CHECK-NEXT: [[B:%.*]] = fsub float [[X]], [[Z:%.*]]
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], float [[B]], float [[Y:%.*]]
; CHECK-NEXT: ret float [[C]]
;
%A = fcmp oeq float %x, 1.0
%B = fsub float %x, %z
%C = select i1 %A, float %B, float %y
ret float %C
}
define i32 @select_sub_icmp_bad(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @select_sub_icmp_bad(
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], 1
; CHECK-NEXT: [[B:%.*]] = sub i32 [[X]], [[Z:%.*]]
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 [[Y:%.*]]
; CHECK-NEXT: ret i32 [[C]]
;
%A = icmp eq i32 %x, 1
%B = sub i32 %x, %z
%C = select i1 %A, i32 %B, i32 %y
ret i32 %C
}
define i32 @select_sub_icmp_bad_sub_inv(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @select_sub_icmp_bad_sub_inv(
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], 0
; CHECK-NEXT: [[B:%.*]] = sub i32 [[Z:%.*]], [[X]]
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 [[Y:%.*]]
; CHECK-NEXT: ret i32 [[C]]
;
%A = icmp eq i32 %x, 0
%B = sub i32 %z, %x
%C = select i1 %A, i32 %B, i32 %y
ret i32 %C
}
define i32 @select_shl_icmp_bad(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @select_shl_icmp_bad(
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], 1
; CHECK-NEXT: [[B:%.*]] = shl i32 [[X]], [[Z:%.*]]
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 [[Y:%.*]]
; CHECK-NEXT: ret i32 [[C]]
;
%A = icmp eq i32 %x, 1
%B = shl i32 %x, %z
%C = select i1 %A, i32 %B, i32 %y
ret i32 %C
}
define i32 @select_lshr_icmp_bad(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @select_lshr_icmp_bad(
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], 1
; CHECK-NEXT: [[B:%.*]] = lshr i32 [[X]], [[Z:%.*]]
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 [[Y:%.*]]
; CHECK-NEXT: ret i32 [[C]]
;
%A = icmp eq i32 %x, 1
%B = lshr i32 %x, %z
%C = select i1 %A, i32 %B, i32 %y
ret i32 %C
}
define i32 @select_ashr_icmp_bad(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @select_ashr_icmp_bad(
; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], 1
; CHECK-NEXT: [[B:%.*]] = ashr i32 [[X]], [[Z:%.*]]
; CHECK-NEXT: [[C:%.*]] = select i1 [[A]], i32 [[B]], i32 [[Y:%.*]]
; CHECK-NEXT: ret i32 [[C]]
;
%A = icmp eq i32 %x, 1
%B = ashr i32 %x, %z
%C = select i1 %A, i32 %B, i32 %y
ret i32 %C
}
!0 = !{!"branch_weights", i32 2, i32 10}