Change all the cstval_pred_ty based PatternMatch helpers (things like m_AllOnes and m_Zero) to only allow poison elements inside vector splats, not undef elements. Historically, we used to represent non-demanded elements in vectors using undef. Nowadays, we use poison instead. As such, I believe that support for undef in vector splats is no longer useful. At the same time, while poison splat elements are pretty much always safe to ignore, this is not generally the case for undef elements. We have existing miscompiles in our tests due to this (see the masked-merge-*.ll tests changed here) and it's easy to miss such cases in the future, now that we write tests using poison instead of undef elements. I think overall, keeping support for undef elements no longer makes sense, and we should drop it. Once this is done consistently, I think we may also consider allowing poison in m_APInt by default, as doing that change is much less risky than doing the same with undef. This change involves a substantial amount of test changes. For most tests, I've just replaced undef with poison, as I don't think there is value in retaining both. For some tests (where the distinction between undef and poison is important), I've duplicated tests.
197 lines
6.4 KiB
LLVM
197 lines
6.4 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
|
|
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
|
|
|
|
; Perform the shift first and merge the truncs as long as all zero/sign
|
|
; bits created by the shift are removed by the trunc.
|
|
|
|
declare void @use(i32)
|
|
|
|
define i8 @trunc_lshr_trunc(i64 %a) {
|
|
; CHECK-LABEL: @trunc_lshr_trunc(
|
|
; CHECK-NEXT: [[C1:%.*]] = lshr i64 [[A:%.*]], 8
|
|
; CHECK-NEXT: [[D:%.*]] = trunc i64 [[C1]] to i8
|
|
; CHECK-NEXT: ret i8 [[D]]
|
|
;
|
|
%b = trunc i64 %a to i32
|
|
%c = lshr i32 %b, 8
|
|
%d = trunc i32 %c to i8
|
|
ret i8 %d
|
|
}
|
|
|
|
define <2 x i8> @trunc_shl_trunc(<2 x i64> %a) {
|
|
; CHECK-LABEL: @trunc_shl_trunc(
|
|
; CHECK-NEXT: [[B:%.*]] = trunc <2 x i64> [[A:%.*]] to <2 x i32>
|
|
; CHECK-NEXT: [[C:%.*]] = shl <2 x i32> [[B]], <i32 9, i32 7>
|
|
; CHECK-NEXT: [[D:%.*]] = trunc <2 x i32> [[C]] to <2 x i8>
|
|
; CHECK-NEXT: ret <2 x i8> [[D]]
|
|
;
|
|
%b = trunc <2 x i64> %a to <2 x i32>
|
|
%c = shl <2 x i32> %b, <i32 9, i32 7>
|
|
%d = trunc <2 x i32> %c to <2 x i8>
|
|
ret <2 x i8> %d
|
|
}
|
|
|
|
define <2 x i8> @trunc_lshr_trunc_uniform(<2 x i64> %a) {
|
|
; CHECK-LABEL: @trunc_lshr_trunc_uniform(
|
|
; CHECK-NEXT: [[C1:%.*]] = lshr <2 x i64> [[A:%.*]], <i64 8, i64 8>
|
|
; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[C1]] to <2 x i8>
|
|
; CHECK-NEXT: ret <2 x i8> [[D]]
|
|
;
|
|
%b = trunc <2 x i64> %a to <2 x i32>
|
|
%c = lshr <2 x i32> %b, <i32 8, i32 8>
|
|
%d = trunc <2 x i32> %c to <2 x i8>
|
|
ret <2 x i8> %d
|
|
}
|
|
|
|
define <2 x i8> @trunc_lshr_trunc_nonuniform(<2 x i64> %a) {
|
|
; CHECK-LABEL: @trunc_lshr_trunc_nonuniform(
|
|
; CHECK-NEXT: [[C1:%.*]] = lshr <2 x i64> [[A:%.*]], <i64 8, i64 2>
|
|
; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[C1]] to <2 x i8>
|
|
; CHECK-NEXT: ret <2 x i8> [[D]]
|
|
;
|
|
%b = trunc <2 x i64> %a to <2 x i32>
|
|
%c = lshr <2 x i32> %b, <i32 8, i32 2>
|
|
%d = trunc <2 x i32> %c to <2 x i8>
|
|
ret <2 x i8> %d
|
|
}
|
|
|
|
define <2 x i8> @trunc_lshr_trunc_uniform_poison(<2 x i64> %a) {
|
|
; CHECK-LABEL: @trunc_lshr_trunc_uniform_poison(
|
|
; CHECK-NEXT: [[C1:%.*]] = lshr <2 x i64> [[A:%.*]], <i64 24, i64 poison>
|
|
; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[C1]] to <2 x i8>
|
|
; CHECK-NEXT: ret <2 x i8> [[D]]
|
|
;
|
|
%b = trunc <2 x i64> %a to <2 x i32>
|
|
%c = lshr <2 x i32> %b, <i32 24, i32 poison>
|
|
%d = trunc <2 x i32> %c to <2 x i8>
|
|
ret <2 x i8> %d
|
|
}
|
|
|
|
define i8 @trunc_lshr_trunc_outofrange(i64 %a) {
|
|
; CHECK-LABEL: @trunc_lshr_trunc_outofrange(
|
|
; CHECK-NEXT: [[B:%.*]] = trunc i64 [[A:%.*]] to i32
|
|
; CHECK-NEXT: [[C:%.*]] = lshr i32 [[B]], 25
|
|
; CHECK-NEXT: [[D:%.*]] = trunc nuw nsw i32 [[C]] to i8
|
|
; CHECK-NEXT: ret i8 [[D]]
|
|
;
|
|
%b = trunc i64 %a to i32
|
|
%c = lshr i32 %b, 25
|
|
%d = trunc i32 %c to i8
|
|
ret i8 %d
|
|
}
|
|
|
|
define <2 x i8> @trunc_lshr_trunc_nonuniform_outofrange(<2 x i64> %a) {
|
|
; CHECK-LABEL: @trunc_lshr_trunc_nonuniform_outofrange(
|
|
; CHECK-NEXT: [[B:%.*]] = trunc <2 x i64> [[A:%.*]] to <2 x i32>
|
|
; CHECK-NEXT: [[C:%.*]] = lshr <2 x i32> [[B]], <i32 8, i32 25>
|
|
; CHECK-NEXT: [[D:%.*]] = trunc <2 x i32> [[C]] to <2 x i8>
|
|
; CHECK-NEXT: ret <2 x i8> [[D]]
|
|
;
|
|
%b = trunc <2 x i64> %a to <2 x i32>
|
|
%c = lshr <2 x i32> %b, <i32 8, i32 25>
|
|
%d = trunc <2 x i32> %c to <2 x i8>
|
|
ret <2 x i8> %d
|
|
}
|
|
|
|
define i8 @trunc_ashr_trunc(i64 %a) {
|
|
; CHECK-LABEL: @trunc_ashr_trunc(
|
|
; CHECK-NEXT: [[TMP1:%.*]] = lshr i64 [[A:%.*]], 8
|
|
; CHECK-NEXT: [[D:%.*]] = trunc i64 [[TMP1]] to i8
|
|
; CHECK-NEXT: ret i8 [[D]]
|
|
;
|
|
%b = trunc i64 %a to i32
|
|
%c = ashr i32 %b, 8
|
|
%d = trunc i32 %c to i8
|
|
ret i8 %d
|
|
}
|
|
|
|
define i8 @trunc_ashr_trunc_exact(i64 %a) {
|
|
; CHECK-LABEL: @trunc_ashr_trunc_exact(
|
|
; CHECK-NEXT: [[TMP1:%.*]] = lshr exact i64 [[A:%.*]], 8
|
|
; CHECK-NEXT: [[D:%.*]] = trunc i64 [[TMP1]] to i8
|
|
; CHECK-NEXT: ret i8 [[D]]
|
|
;
|
|
%b = trunc i64 %a to i32
|
|
%c = ashr exact i32 %b, 8
|
|
%d = trunc i32 %c to i8
|
|
ret i8 %d
|
|
}
|
|
|
|
define <2 x i8> @trunc_ashr_trunc_uniform(<2 x i64> %a) {
|
|
; CHECK-LABEL: @trunc_ashr_trunc_uniform(
|
|
; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i64> [[A:%.*]], <i64 8, i64 8>
|
|
; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[TMP1]] to <2 x i8>
|
|
; CHECK-NEXT: ret <2 x i8> [[D]]
|
|
;
|
|
%b = trunc <2 x i64> %a to <2 x i32>
|
|
%c = ashr <2 x i32> %b, <i32 8, i32 8>
|
|
%d = trunc <2 x i32> %c to <2 x i8>
|
|
ret <2 x i8> %d
|
|
}
|
|
|
|
define <2 x i8> @trunc_ashr_trunc_nonuniform(<2 x i64> %a) {
|
|
; CHECK-LABEL: @trunc_ashr_trunc_nonuniform(
|
|
; CHECK-NEXT: [[C1:%.*]] = ashr <2 x i64> [[A:%.*]], <i64 0, i64 23>
|
|
; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[C1]] to <2 x i8>
|
|
; CHECK-NEXT: ret <2 x i8> [[D]]
|
|
;
|
|
%b = trunc <2 x i64> %a to <2 x i32>
|
|
%c = ashr <2 x i32> %b, <i32 0, i32 23>
|
|
%d = trunc <2 x i32> %c to <2 x i8>
|
|
ret <2 x i8> %d
|
|
}
|
|
|
|
define <2 x i8> @trunc_ashr_trunc_uniform_poison(<2 x i64> %a) {
|
|
; CHECK-LABEL: @trunc_ashr_trunc_uniform_poison(
|
|
; CHECK-NEXT: [[C1:%.*]] = ashr <2 x i64> [[A:%.*]], <i64 8, i64 poison>
|
|
; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[C1]] to <2 x i8>
|
|
; CHECK-NEXT: ret <2 x i8> [[D]]
|
|
;
|
|
%b = trunc <2 x i64> %a to <2 x i32>
|
|
%c = ashr <2 x i32> %b, <i32 8, i32 poison>
|
|
%d = trunc <2 x i32> %c to <2 x i8>
|
|
ret <2 x i8> %d
|
|
}
|
|
|
|
define i8 @trunc_ashr_trunc_outofrange(i64 %a) {
|
|
; CHECK-LABEL: @trunc_ashr_trunc_outofrange(
|
|
; CHECK-NEXT: [[B:%.*]] = trunc i64 [[A:%.*]] to i32
|
|
; CHECK-NEXT: [[C:%.*]] = ashr i32 [[B]], 25
|
|
; CHECK-NEXT: [[D:%.*]] = trunc nsw i32 [[C]] to i8
|
|
; CHECK-NEXT: ret i8 [[D]]
|
|
;
|
|
%b = trunc i64 %a to i32
|
|
%c = ashr i32 %b, 25
|
|
%d = trunc i32 %c to i8
|
|
ret i8 %d
|
|
}
|
|
|
|
define <2 x i8> @trunc_ashr_trunc_nonuniform_outofrange(<2 x i64> %a) {
|
|
; CHECK-LABEL: @trunc_ashr_trunc_nonuniform_outofrange(
|
|
; CHECK-NEXT: [[B:%.*]] = trunc <2 x i64> [[A:%.*]] to <2 x i32>
|
|
; CHECK-NEXT: [[C:%.*]] = ashr <2 x i32> [[B]], <i32 8, i32 25>
|
|
; CHECK-NEXT: [[D:%.*]] = trunc <2 x i32> [[C]] to <2 x i8>
|
|
; CHECK-NEXT: ret <2 x i8> [[D]]
|
|
;
|
|
%b = trunc <2 x i64> %a to <2 x i32>
|
|
%c = ashr <2 x i32> %b, <i32 8, i32 25>
|
|
%d = trunc <2 x i32> %c to <2 x i8>
|
|
ret <2 x i8> %d
|
|
}
|
|
|
|
define i8 @trunc_ashr_trunc_multiuse(i64 %a) {
|
|
; CHECK-LABEL: @trunc_ashr_trunc_multiuse(
|
|
; CHECK-NEXT: [[B:%.*]] = trunc i64 [[A:%.*]] to i32
|
|
; CHECK-NEXT: [[C:%.*]] = ashr i32 [[B]], 9
|
|
; CHECK-NEXT: [[D:%.*]] = trunc i32 [[C]] to i8
|
|
; CHECK-NEXT: call void @use(i32 [[C]])
|
|
; CHECK-NEXT: ret i8 [[D]]
|
|
;
|
|
%b = trunc i64 %a to i32
|
|
%c = ashr i32 %b, 9
|
|
%d = trunc i32 %c to i8
|
|
call void @use(i32 %c)
|
|
ret i8 %d
|
|
}
|