182 return progress;
183 }
184
185 //------------------------------Value-----------------------------------------
186 const Type* MulNode::Value(PhaseGVN* phase) const {
187 const Type *t1 = phase->type( in(1) );
188 const Type *t2 = phase->type( in(2) );
189 // Either input is TOP ==> the result is TOP
190 if( t1 == Type::TOP ) return Type::TOP;
191 if( t2 == Type::TOP ) return Type::TOP;
192
193 // Either input is ZERO ==> the result is ZERO.
194 // Not valid for floats or doubles since +0.0 * -0.0 --> +0.0
195 int op = Opcode();
196 if( op == Op_MulI || op == Op_AndI || op == Op_MulL || op == Op_AndL ) {
197 const Type *zero = add_id(); // The multiplicative zero
198 if( t1->higher_equal( zero ) ) return zero;
199 if( t2->higher_equal( zero ) ) return zero;
200 }
201
202 // Either input is BOTTOM ==> the result is the local BOTTOM
203 if( t1 == Type::BOTTOM || t2 == Type::BOTTOM )
204 return bottom_type();
205
206 return mul_ring(t1,t2); // Local flavor of type multiplication
207 }
208
209 MulNode* MulNode::make(Node* in1, Node* in2, BasicType bt) {
210 switch (bt) {
211 case T_INT:
212 return new MulINode(in1, in2);
213 case T_LONG:
214 return new MulLNode(in1, in2);
215 default:
216 fatal("Not implemented for %s", type2name(bt));
217 }
218 return nullptr;
219 }
220
221 MulNode* MulNode::make_and(Node* in1, Node* in2, BasicType bt) {
844
845 // Masking off sign bits? Dont make them!
846 if (op == Op_RShiftL) {
847 const TypeInt* t12 = phase->type(in1->in(2))->isa_int();
848 if( t12 && t12->is_con() ) { // Shift is by a constant
849 int shift = t12->get_con();
850 shift &= BitsPerJavaLong - 1; // semantics of Java shifts
851 if (shift != 0) {
852 const julong sign_bits_mask = ~(((julong)CONST64(1) << (julong)(BitsPerJavaLong - shift)) -1);
853 // If the AND'ing of the 2 masks has no bits, then only original shifted
854 // bits survive. NO sign-extension bits survive the maskings.
855 if( (sign_bits_mask & mask) == 0 ) {
856 // Use zero-fill shift instead
857 Node *zshift = phase->transform(new URShiftLNode(in1->in(1), in1->in(2)));
858 return new AndLNode(zshift, in(2));
859 }
860 }
861 }
862 }
863
864 return MulNode::Ideal(phase, can_reshape);
865 }
866
867 LShiftNode* LShiftNode::make(Node* in1, Node* in2, BasicType bt) {
868 switch (bt) {
869 case T_INT:
870 return new LShiftINode(in1, in2);
871 case T_LONG:
872 return new LShiftLNode(in1, in2);
873 default:
874 fatal("Not implemented for %s", type2name(bt));
875 }
876 return nullptr;
877 }
878
879 // Returns whether the shift amount is constant. If so, sets count.
880 static bool const_shift_count(PhaseGVN* phase, const Node* shift_node, int* count) {
881 const TypeInt* tcount = phase->type(shift_node->in(2))->isa_int();
882 if (tcount != nullptr && tcount->is_con()) {
883 *count = tcount->get_con();
|
182 return progress;
183 }
184
185 //------------------------------Value-----------------------------------------
186 const Type* MulNode::Value(PhaseGVN* phase) const {
187 const Type *t1 = phase->type( in(1) );
188 const Type *t2 = phase->type( in(2) );
189 // Either input is TOP ==> the result is TOP
190 if( t1 == Type::TOP ) return Type::TOP;
191 if( t2 == Type::TOP ) return Type::TOP;
192
193 // Either input is ZERO ==> the result is ZERO.
194 // Not valid for floats or doubles since +0.0 * -0.0 --> +0.0
195 int op = Opcode();
196 if( op == Op_MulI || op == Op_AndI || op == Op_MulL || op == Op_AndL ) {
197 const Type *zero = add_id(); // The multiplicative zero
198 if( t1->higher_equal( zero ) ) return zero;
199 if( t2->higher_equal( zero ) ) return zero;
200 }
201
202 // TODO 8350865 Still needed? Yes, I think this is from PhaseMacroExpand::expand_mh_intrinsic_return
203 // Code pattern on return from a call that returns an __Value. Can
204 // be optimized away if the return value turns out to be an oop.
205 if (op == Op_AndX &&
206 in(1) != nullptr &&
207 in(1)->Opcode() == Op_CastP2X &&
208 in(1)->in(1) != nullptr &&
209 phase->type(in(1)->in(1))->isa_oopptr() &&
210 t2->isa_intptr_t()->_lo >= 0 &&
211 t2->isa_intptr_t()->_hi <= MinObjAlignmentInBytesMask) {
212 return add_id();
213 }
214
215 // Either input is BOTTOM ==> the result is the local BOTTOM
216 if( t1 == Type::BOTTOM || t2 == Type::BOTTOM )
217 return bottom_type();
218
219 return mul_ring(t1,t2); // Local flavor of type multiplication
220 }
221
222 MulNode* MulNode::make(Node* in1, Node* in2, BasicType bt) {
223 switch (bt) {
224 case T_INT:
225 return new MulINode(in1, in2);
226 case T_LONG:
227 return new MulLNode(in1, in2);
228 default:
229 fatal("Not implemented for %s", type2name(bt));
230 }
231 return nullptr;
232 }
233
234 MulNode* MulNode::make_and(Node* in1, Node* in2, BasicType bt) {
857
858 // Masking off sign bits? Dont make them!
859 if (op == Op_RShiftL) {
860 const TypeInt* t12 = phase->type(in1->in(2))->isa_int();
861 if( t12 && t12->is_con() ) { // Shift is by a constant
862 int shift = t12->get_con();
863 shift &= BitsPerJavaLong - 1; // semantics of Java shifts
864 if (shift != 0) {
865 const julong sign_bits_mask = ~(((julong)CONST64(1) << (julong)(BitsPerJavaLong - shift)) -1);
866 // If the AND'ing of the 2 masks has no bits, then only original shifted
867 // bits survive. NO sign-extension bits survive the maskings.
868 if( (sign_bits_mask & mask) == 0 ) {
869 // Use zero-fill shift instead
870 Node *zshift = phase->transform(new URShiftLNode(in1->in(1), in1->in(2)));
871 return new AndLNode(zshift, in(2));
872 }
873 }
874 }
875 }
876
877 // Search for GraphKit::mark_word_test patterns and fold the test if the result is statically known
878 Node* load1 = in(1);
879 Node* load2 = nullptr;
880 if (load1->is_Phi() && phase->type(load1)->isa_long()) {
881 load1 = in(1)->in(1);
882 load2 = in(1)->in(2);
883 }
884 if (load1 != nullptr && load1->is_Load() && phase->type(load1)->isa_long() &&
885 (load2 == nullptr || (load2->is_Load() && phase->type(load2)->isa_long()))) {
886 const TypePtr* adr_t1 = phase->type(load1->in(MemNode::Address))->isa_ptr();
887 const TypePtr* adr_t2 = (load2 != nullptr) ? phase->type(load2->in(MemNode::Address))->isa_ptr() : nullptr;
888 if (adr_t1 != nullptr && adr_t1->offset() == oopDesc::mark_offset_in_bytes() &&
889 (load2 == nullptr || (adr_t2 != nullptr && adr_t2->offset() == in_bytes(Klass::prototype_header_offset())))) {
890 if (mask == markWord::inline_type_pattern) {
891 if (adr_t1->is_inlinetypeptr()) {
892 set_req_X(1, in(2), phase);
893 return this;
894 } else if (!adr_t1->can_be_inline_type()) {
895 set_req_X(1, phase->longcon(0), phase);
896 return this;
897 }
898 } else if (mask == markWord::null_free_array_bit_in_place) {
899 if (adr_t1->is_null_free()) {
900 set_req_X(1, in(2), phase);
901 return this;
902 } else if (adr_t1->is_not_null_free()) {
903 set_req_X(1, phase->longcon(0), phase);
904 return this;
905 }
906 } else if (mask == markWord::flat_array_bit_in_place) {
907 if (adr_t1->is_flat()) {
908 set_req_X(1, in(2), phase);
909 return this;
910 } else if (adr_t1->is_not_flat()) {
911 set_req_X(1, phase->longcon(0), phase);
912 return this;
913 }
914 }
915 }
916 }
917
918 return MulNode::Ideal(phase, can_reshape);
919 }
920
921 LShiftNode* LShiftNode::make(Node* in1, Node* in2, BasicType bt) {
922 switch (bt) {
923 case T_INT:
924 return new LShiftINode(in1, in2);
925 case T_LONG:
926 return new LShiftLNode(in1, in2);
927 default:
928 fatal("Not implemented for %s", type2name(bt));
929 }
930 return nullptr;
931 }
932
933 // Returns whether the shift amount is constant. If so, sets count.
934 static bool const_shift_count(PhaseGVN* phase, const Node* shift_node, int* count) {
935 const TypeInt* tcount = phase->type(shift_node->in(2))->isa_int();
936 if (tcount != nullptr && tcount->is_con()) {
937 *count = tcount->get_con();
|