mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 19:23:23 +01:00
[InstCombine] peek through unsigned FP casts for zero-equality compares (PR36682)
Summary: This pattern came up in PR36682 / D44390 https://bugs.llvm.org/show_bug.cgi?id=36682 https://reviews.llvm.org/D44390 https://godbolt.org/g/oKvT5H See also D44416 Reviewers: spatel, majnemer, efriedma, arsenm Reviewed By: spatel Subscribers: wdng, llvm-commits Differential Revision: https://reviews.llvm.org/D44424 llvm-svn: 327799
This commit is contained in:
parent
48886c59e8
commit
9134a6bbeb
@ -4506,6 +4506,15 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
|
||||
return New;
|
||||
}
|
||||
|
||||
Value *X;
|
||||
|
||||
// Zero-equality checks are preserved through unsigned floating-point casts:
|
||||
// icmp eq (bitcast (uitofp X)), 0 --> icmp eq X, 0
|
||||
// icmp ne (bitcast (uitofp X)), 0 --> icmp ne X, 0
|
||||
if (match(Op0, m_BitCast(m_UIToFP(m_Value(X)))))
|
||||
if (I.isEquality() && match(Op1, m_Zero()))
|
||||
return new ICmpInst(Pred, X, ConstantInt::getNullValue(X->getType()));
|
||||
|
||||
// Test to see if the operands of the icmp are casted versions of other
|
||||
// values. If the ptr->ptr cast can be stripped off both arguments, we do so
|
||||
// now.
|
||||
|
@ -1,18 +1,16 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
||||
; RUN: opt < %s -instcombine -S | FileCheck %s
|
||||
|
||||
; target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
|
||||
; This is related to https://bugs.llvm.org/show_bug.cgi?id=36682
|
||||
|
||||
; FIXME: *all* of these are true tests.
|
||||
; In *all* of these, uitofp and bitcast should be instcombine'd out.
|
||||
|
||||
; FIXME: icmp eq/ne does not ignore undef elements in vectors.
|
||||
|
||||
define i1 @i32_cast_cmp_eq_int_0_uitofp_float(i32 %i) {
|
||||
; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_float(
|
||||
; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to float
|
||||
; CHECK-NEXT: [[B:%.*]] = bitcast float [[F]] to i32
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[B]], 0
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I:%.*]], 0
|
||||
; CHECK-NEXT: ret i1 [[CMP]]
|
||||
;
|
||||
%f = uitofp i32 %i to float
|
||||
@ -23,9 +21,7 @@ define i1 @i32_cast_cmp_eq_int_0_uitofp_float(i32 %i) {
|
||||
|
||||
define <2 x i1> @i32_cast_cmp_eq_int_0_uitofp_float_vec(<2 x i32> %i) {
|
||||
; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_float_vec(
|
||||
; CHECK-NEXT: [[F:%.*]] = uitofp <2 x i32> [[I:%.*]] to <2 x float>
|
||||
; CHECK-NEXT: [[B:%.*]] = bitcast <2 x float> [[F]] to <2 x i32>
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[B]], zeroinitializer
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[I:%.*]], zeroinitializer
|
||||
; CHECK-NEXT: ret <2 x i1> [[CMP]]
|
||||
;
|
||||
%f = uitofp <2 x i32> %i to <2 x float>
|
||||
@ -49,9 +45,7 @@ define <3 x i1> @i32_cast_cmp_eq_int_0_uitofp_float_vec_undef(<3 x i32> %i) {
|
||||
|
||||
define i1 @i32_cast_cmp_ne_int_0_uitofp_float(i32 %i) {
|
||||
; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_float(
|
||||
; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to float
|
||||
; CHECK-NEXT: [[B:%.*]] = bitcast float [[F]] to i32
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[B]], 0
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[I:%.*]], 0
|
||||
; CHECK-NEXT: ret i1 [[CMP]]
|
||||
;
|
||||
%f = uitofp i32 %i to float
|
||||
@ -62,9 +56,7 @@ define i1 @i32_cast_cmp_ne_int_0_uitofp_float(i32 %i) {
|
||||
|
||||
define <2 x i1> @i32_cast_cmp_ne_int_0_uitofp_float_vec(<2 x i32> %i) {
|
||||
; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_float_vec(
|
||||
; CHECK-NEXT: [[F:%.*]] = uitofp <2 x i32> [[I:%.*]] to <2 x float>
|
||||
; CHECK-NEXT: [[B:%.*]] = bitcast <2 x float> [[F]] to <2 x i32>
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[B]], zeroinitializer
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[I:%.*]], zeroinitializer
|
||||
; CHECK-NEXT: ret <2 x i1> [[CMP]]
|
||||
;
|
||||
%f = uitofp <2 x i32> %i to <2 x float>
|
||||
@ -88,9 +80,7 @@ define <3 x i1> @i32_cast_cmp_ne_int_0_uitofp_float_vec_undef(<3 x i32> %i) {
|
||||
|
||||
define i1 @i32_cast_cmp_eq_int_0_uitofp_double(i32 %i) {
|
||||
; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_double(
|
||||
; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to double
|
||||
; CHECK-NEXT: [[B:%.*]] = bitcast double [[F]] to i64
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[B]], 0
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I:%.*]], 0
|
||||
; CHECK-NEXT: ret i1 [[CMP]]
|
||||
;
|
||||
%f = uitofp i32 %i to double
|
||||
@ -101,9 +91,7 @@ define i1 @i32_cast_cmp_eq_int_0_uitofp_double(i32 %i) {
|
||||
|
||||
define <2 x i1> @i32_cast_cmp_eq_int_0_uitofp_double_vec(<2 x i32> %i) {
|
||||
; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_double_vec(
|
||||
; CHECK-NEXT: [[F:%.*]] = uitofp <2 x i32> [[I:%.*]] to <2 x double>
|
||||
; CHECK-NEXT: [[B:%.*]] = bitcast <2 x double> [[F]] to <2 x i64>
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i64> [[B]], zeroinitializer
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[I:%.*]], zeroinitializer
|
||||
; CHECK-NEXT: ret <2 x i1> [[CMP]]
|
||||
;
|
||||
%f = uitofp <2 x i32> %i to <2 x double>
|
||||
@ -127,9 +115,7 @@ define <3 x i1> @i32_cast_cmp_eq_int_0_uitofp_double_vec_undef(<3 x i32> %i) {
|
||||
|
||||
define i1 @i32_cast_cmp_ne_int_0_uitofp_double(i32 %i) {
|
||||
; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_double(
|
||||
; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to double
|
||||
; CHECK-NEXT: [[B:%.*]] = bitcast double [[F]] to i64
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i64 [[B]], 0
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[I:%.*]], 0
|
||||
; CHECK-NEXT: ret i1 [[CMP]]
|
||||
;
|
||||
%f = uitofp i32 %i to double
|
||||
@ -140,9 +126,7 @@ define i1 @i32_cast_cmp_ne_int_0_uitofp_double(i32 %i) {
|
||||
|
||||
define <2 x i1> @i32_cast_cmp_ne_int_0_uitofp_double_vec(<2 x i32> %i) {
|
||||
; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_double_vec(
|
||||
; CHECK-NEXT: [[F:%.*]] = uitofp <2 x i32> [[I:%.*]] to <2 x double>
|
||||
; CHECK-NEXT: [[B:%.*]] = bitcast <2 x double> [[F]] to <2 x i64>
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i64> [[B]], zeroinitializer
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[I:%.*]], zeroinitializer
|
||||
; CHECK-NEXT: ret <2 x i1> [[CMP]]
|
||||
;
|
||||
%f = uitofp <2 x i32> %i to <2 x double>
|
||||
@ -166,9 +150,7 @@ define <3 x i1> @i32_cast_cmp_ne_int_0_uitofp_double_vec_undef(<3 x i32> %i) {
|
||||
|
||||
define i1 @i32_cast_cmp_eq_int_0_uitofp_half(i32 %i) {
|
||||
; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_half(
|
||||
; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to half
|
||||
; CHECK-NEXT: [[B:%.*]] = bitcast half [[F]] to i16
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i16 [[B]], 0
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I:%.*]], 0
|
||||
; CHECK-NEXT: ret i1 [[CMP]]
|
||||
;
|
||||
%f = uitofp i32 %i to half
|
||||
@ -179,9 +161,7 @@ define i1 @i32_cast_cmp_eq_int_0_uitofp_half(i32 %i) {
|
||||
|
||||
define <2 x i1> @i32_cast_cmp_eq_int_0_uitofp_half_vec(<2 x i32> %i) {
|
||||
; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_half_vec(
|
||||
; CHECK-NEXT: [[F:%.*]] = uitofp <2 x i32> [[I:%.*]] to <2 x half>
|
||||
; CHECK-NEXT: [[B:%.*]] = bitcast <2 x half> [[F]] to <2 x i16>
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i16> [[B]], zeroinitializer
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[I:%.*]], zeroinitializer
|
||||
; CHECK-NEXT: ret <2 x i1> [[CMP]]
|
||||
;
|
||||
%f = uitofp <2 x i32> %i to <2 x half>
|
||||
@ -205,9 +185,7 @@ define <3 x i1> @i32_cast_cmp_eq_int_0_uitofp_half_vec_undef(<3 x i32> %i) {
|
||||
|
||||
define i1 @i32_cast_cmp_ne_int_0_uitofp_half(i32 %i) {
|
||||
; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_half(
|
||||
; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to half
|
||||
; CHECK-NEXT: [[B:%.*]] = bitcast half [[F]] to i16
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i16 [[B]], 0
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[I:%.*]], 0
|
||||
; CHECK-NEXT: ret i1 [[CMP]]
|
||||
;
|
||||
%f = uitofp i32 %i to half
|
||||
@ -218,9 +196,7 @@ define i1 @i32_cast_cmp_ne_int_0_uitofp_half(i32 %i) {
|
||||
|
||||
define <2 x i1> @i32_cast_cmp_ne_int_0_uitofp_half_vec(<2 x i32> %i) {
|
||||
; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_half_vec(
|
||||
; CHECK-NEXT: [[F:%.*]] = uitofp <2 x i32> [[I:%.*]] to <2 x half>
|
||||
; CHECK-NEXT: [[B:%.*]] = bitcast <2 x half> [[F]] to <2 x i16>
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i16> [[B]], zeroinitializer
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[I:%.*]], zeroinitializer
|
||||
; CHECK-NEXT: ret <2 x i1> [[CMP]]
|
||||
;
|
||||
%f = uitofp <2 x i32> %i to <2 x half>
|
||||
|
Loading…
Reference in New Issue
Block a user