Skip to content

Commit

Permalink
[InstCombine] add tests for icmp with trunc op; NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
rotateright committed Nov 3, 2021
1 parent 34b903d commit d18b7ea
Showing 1 changed file with 50 additions and 12 deletions.
62 changes: 50 additions & 12 deletions llvm/test/Transforms/InstCombine/icmp-trunc.ll
Expand Up @@ -91,8 +91,6 @@ define <2 x i1> @ult_2044_splat(<2 x i16> %x) {
ret <2 x i1> %r
}

; negative test - need high-bit-mask constant

define i1 @ult_96(i32 %x) {
; CHECK-LABEL: @ult_96(
; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
Expand All @@ -104,8 +102,6 @@ define i1 @ult_96(i32 %x) {
ret i1 %r
}

; negative test - no extra use allowed

define i1 @ult_192_use(i32 %x) {
; CHECK-LABEL: @ult_192_use(
; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
Expand All @@ -119,6 +115,52 @@ define i1 @ult_192_use(i32 %x) {
ret i1 %r
}

define i1 @ugt_3(i32 %x) {
; CHECK-LABEL: @ugt_3(
; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[T]], 3
; CHECK-NEXT: ret i1 [[R]]
;
%t = trunc i32 %x to i8
%r = icmp ugt i8 %t, 3
ret i1 %r
}

define <2 x i1> @ugt_7_splat(<2 x i16> %x) {
; CHECK-LABEL: @ugt_7_splat(
; CHECK-NEXT: [[T:%.*]] = trunc <2 x i16> [[X:%.*]] to <2 x i11>
; CHECK-NEXT: [[R:%.*]] = icmp ugt <2 x i11> [[T]], <i11 7, i11 7>
; CHECK-NEXT: ret <2 x i1> [[R]]
;
%t = trunc <2 x i16> %x to <2 x i11>
%r = icmp ugt <2 x i11> %t, <i11 7, i11 7>
ret <2 x i1> %r
}

define i1 @ugt_4(i32 %x) {
; CHECK-LABEL: @ugt_4(
; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[T]], 4
; CHECK-NEXT: ret i1 [[R]]
;
%t = trunc i32 %x to i8
%r = icmp ugt i8 %t, 4
ret i1 %r
}

define i1 @ugt_3_use(i32 %x) {
; CHECK-LABEL: @ugt_3_use(
; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
; CHECK-NEXT: call void @use(i8 [[T]])
; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[T]], 3
; CHECK-NEXT: ret i1 [[R]]
;
%t = trunc i32 %x to i8
call void @use(i8 %t)
%r = icmp ugt i8 %t, 3
ret i1 %r
}

define i1 @ugt_253(i32 %x) {
; CHECK-LABEL: @ugt_253(
; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
Expand All @@ -141,10 +183,8 @@ define <2 x i1> @ugt_239_splat(<2 x i16> %x) {
ret <2 x i1> %r
}

; negative test - need inverted power-of-2 constant

define i1 @ugt_3(i32 %x) {
; CHECK-LABEL: @ugt_3(
define i1 @ugt_252(i32 %x) {
; CHECK-LABEL: @ugt_252(
; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[T]], -4
; CHECK-NEXT: ret i1 [[R]]
Expand All @@ -154,10 +194,8 @@ define i1 @ugt_3(i32 %x) {
ret i1 %r
}

; negative test - no extra use allowed

define i1 @ugt_2_use(i32 %x) {
; CHECK-LABEL: @ugt_2_use(
define i1 @ugt_253_use(i32 %x) {
; CHECK-LABEL: @ugt_253_use(
; CHECK-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
; CHECK-NEXT: call void @use(i8 [[T]])
; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[T]], -3
Expand Down

0 comments on commit d18b7ea

Please sign in to comment.