@@ -828,27 +828,42 @@ bool VectorNode::is_vector_shift_count(int opc) {
828
828
}
829
829
}
830
830
831
- static bool is_con_M1 (Node* n) {
831
+ static bool is_con (Node* n, long con ) {
832
832
if (n->is_Con ()) {
833
833
const Type* t = n->bottom_type ();
834
- if (t->isa_int () && t->is_int ()->get_con () == - 1 ) {
834
+ if (t->isa_int () && t->is_int ()->get_con () == ( int )con ) {
835
835
return true ;
836
836
}
837
- if (t->isa_long () && t->is_long ()->get_con () == - 1 ) {
837
+ if (t->isa_long () && t->is_long ()->get_con () == con ) {
838
838
return true ;
839
839
}
840
840
}
841
841
return false ;
842
842
}
843
843
844
+ // Return true if every bit in this vector is 1.
844
845
bool VectorNode::is_all_ones_vector (Node* n) {
845
846
switch (n->Opcode ()) {
846
847
case Op_ReplicateB:
847
848
case Op_ReplicateS:
848
849
case Op_ReplicateI:
849
850
case Op_ReplicateL:
850
851
case Op_MaskAll:
851
- return is_con_M1 (n->in (1 ));
852
+ return is_con (n->in (1 ), -1 );
853
+ default :
854
+ return false ;
855
+ }
856
+ }
857
+
858
+ // Return true if every bit in this vector is 0.
859
+ bool VectorNode::is_all_zeros_vector (Node* n) {
860
+ switch (n->Opcode ()) {
861
+ case Op_ReplicateB:
862
+ case Op_ReplicateS:
863
+ case Op_ReplicateI:
864
+ case Op_ReplicateL:
865
+ case Op_MaskAll:
866
+ return is_con (n->in (1 ), 0 );
852
867
default :
853
868
return false ;
854
869
}
@@ -1776,6 +1791,95 @@ Node* ReverseVNode::Identity(PhaseGVN* phase) {
1776
1791
return this ;
1777
1792
}
1778
1793
1794
+ Node* AndVNode::Identity (PhaseGVN* phase) {
1795
+ // (AndV src (Replicate m1)) => src
1796
+ // (AndVMask src (MaskAll m1)) => src
1797
+ if (VectorNode::is_all_ones_vector (in (2 ))) {
1798
+ return in (1 );
1799
+ }
1800
+ // (AndV (Replicate zero) src) => (Replicate zero)
1801
+ // (AndVMask (MaskAll zero) src) => (MaskAll zero)
1802
+ if (VectorNode::is_all_zeros_vector (in (1 ))) {
1803
+ return in (1 );
1804
+ }
1805
+ // The following transformations are only applied to
1806
+ // the un-predicated operation, since the VectorAPI
1807
+ // masked operation requires the unmasked lanes to
1808
+ // save the same values in the first operand.
1809
+ if (!is_predicated_vector ()) {
1810
+ // (AndV (Replicate m1) src) => src
1811
+ // (AndVMask (MaskAll m1) src) => src
1812
+ if (VectorNode::is_all_ones_vector (in (1 ))) {
1813
+ return in (2 );
1814
+ }
1815
+ // (AndV src (Replicate zero)) => (Replicate zero)
1816
+ // (AndVMask src (MaskAll zero)) => (MaskAll zero)
1817
+ if (VectorNode::is_all_zeros_vector (in (2 ))) {
1818
+ return in (2 );
1819
+ }
1820
+ }
1821
+
1822
+ // (AndV src src) => src
1823
+ // (AndVMask src src) => src
1824
+ if (in (1 ) == in (2 )) {
1825
+ return in (1 );
1826
+ }
1827
+ return this ;
1828
+ }
1829
+
1830
+ Node* OrVNode::Identity (PhaseGVN* phase) {
1831
+ // (OrV (Replicate m1) src) => (Replicate m1)
1832
+ // (OrVMask (MaskAll m1) src) => (MaskAll m1)
1833
+ if (VectorNode::is_all_ones_vector (in (1 ))) {
1834
+ return in (1 );
1835
+ }
1836
+ // (OrV src (Replicate zero)) => src
1837
+ // (OrVMask src (MaskAll zero)) => src
1838
+ if (VectorNode::is_all_zeros_vector (in (2 ))) {
1839
+ return in (1 );
1840
+ }
1841
+ // The following transformations are only applied to
1842
+ // the un-predicated operation, since the VectorAPI
1843
+ // masked operation requires the unmasked lanes to
1844
+ // save the same values in the first operand.
1845
+ if (!is_predicated_vector ()) {
1846
+ // (OrV src (Replicate m1)) => (Replicate m1)
1847
+ // (OrVMask src (MaskAll m1)) => (MaskAll m1)
1848
+ if (VectorNode::is_all_ones_vector (in (2 ))) {
1849
+ return in (2 );
1850
+ }
1851
+ // (OrV (Replicate zero) src) => src
1852
+ // (OrVMask (MaskAll zero) src) => src
1853
+ if (VectorNode::is_all_zeros_vector (in (1 ))) {
1854
+ return in (2 );
1855
+ }
1856
+ }
1857
+
1858
+ // (OrV src src) => src
1859
+ // (OrVMask src src) => src
1860
+ if (in (1 ) == in (2 )) {
1861
+ return in (1 );
1862
+ }
1863
+ return this ;
1864
+ }
1865
+
1866
+ Node* XorVNode::Ideal (PhaseGVN* phase, bool can_reshape) {
1867
+ // (XorV src src) => (Replicate zero)
1868
+ // (XorVMask src src) => (MaskAll zero)
1869
+ //
1870
+ // The transformation is only applied to the un-predicated
1871
+ // operation, since the VectorAPI masked operation requires
1872
+ // the unmasked lanes to save the same values in the first
1873
+ // operand.
1874
+ if (!is_predicated_vector () && (in (1 ) == in (2 ))) {
1875
+ BasicType bt = vect_type ()->element_basic_type ();
1876
+ Node* zero = phase->transform (phase->zerocon (bt));
1877
+ return VectorNode::scalar2vector (zero, length (), Type::get_const_basic_type (bt),
1878
+ bottom_type ()->isa_vectmask () != NULL );
1879
+ }
1880
+ return NULL ;
1881
+ }
1882
+
1779
1883
#ifndef PRODUCT
1780
1884
void VectorBoxAllocateNode::dump_spec (outputStream *st) const {
1781
1885
CallStaticJavaNode::dump_spec (st);
0 commit comments