181 return progress;
182 }
183
184 //------------------------------Value-----------------------------------------
185 const Type* MulNode::Value(PhaseGVN* phase) const {
186 const Type *t1 = phase->type( in(1) );
187 const Type *t2 = phase->type( in(2) );
188 // Either input is TOP ==> the result is TOP
189 if( t1 == Type::TOP ) return Type::TOP;
190 if( t2 == Type::TOP ) return Type::TOP;
191
192 // Either input is ZERO ==> the result is ZERO.
193 // Not valid for floats or doubles since +0.0 * -0.0 --> +0.0
194 int op = Opcode();
195 if( op == Op_MulI || op == Op_AndI || op == Op_MulL || op == Op_AndL ) {
196 const Type *zero = add_id(); // The multiplicative zero
197 if( t1->higher_equal( zero ) ) return zero;
198 if( t2->higher_equal( zero ) ) return zero;
199 }
200
201 // Either input is BOTTOM ==> the result is the local BOTTOM
202 if( t1 == Type::BOTTOM || t2 == Type::BOTTOM )
203 return bottom_type();
204
205 return mul_ring(t1,t2); // Local flavor of type multiplication
206 }
207
208 MulNode* MulNode::make(Node* in1, Node* in2, BasicType bt) {
209 switch (bt) {
210 case T_INT:
211 return new MulINode(in1, in2);
212 case T_LONG:
213 return new MulLNode(in1, in2);
214 default:
215 fatal("Not implemented for %s", type2name(bt));
216 }
217 return nullptr;
218 }
219
220 MulNode* MulNode::make_and(Node* in1, Node* in2, BasicType bt) {
912
913 // Masking off sign bits? Dont make them!
914 if (op == Op_RShiftL) {
915 const TypeInt* t12 = phase->type(in1->in(2))->isa_int();
916 if( t12 && t12->is_con() ) { // Shift is by a constant
917 int shift = t12->get_con();
918 shift &= BitsPerJavaLong - 1; // semantics of Java shifts
919 if (shift != 0) {
920 const julong sign_bits_mask = ~(((julong)CONST64(1) << (julong)(BitsPerJavaLong - shift)) -1);
921 // If the AND'ing of the 2 masks has no bits, then only original shifted
922 // bits survive. NO sign-extension bits survive the maskings.
923 if( (sign_bits_mask & mask) == 0 ) {
924 // Use zero-fill shift instead
925 Node *zshift = phase->transform(new URShiftLNode(in1->in(1), in1->in(2)));
926 return new AndLNode(zshift, in(2));
927 }
928 }
929 }
930 }
931
932 return MulNode::Ideal(phase, can_reshape);
933 }
934
935 LShiftNode* LShiftNode::make(Node* in1, Node* in2, BasicType bt) {
936 switch (bt) {
937 case T_INT:
938 return new LShiftINode(in1, in2);
939 case T_LONG:
940 return new LShiftLNode(in1, in2);
941 default:
942 fatal("Not implemented for %s", type2name(bt));
943 }
944 return nullptr;
945 }
946
947 // Returns whether the shift amount is constant. If so, sets count.
948 static bool const_shift_count(PhaseGVN* phase, const Node* shift_node, int* count) {
949 const TypeInt* tcount = phase->type(shift_node->in(2))->isa_int();
950 if (tcount != nullptr && tcount->is_con()) {
951 *count = tcount->get_con();
|
181 return progress;
182 }
183
184 //------------------------------Value-----------------------------------------
185 const Type* MulNode::Value(PhaseGVN* phase) const {
186 const Type *t1 = phase->type( in(1) );
187 const Type *t2 = phase->type( in(2) );
188 // Either input is TOP ==> the result is TOP
189 if( t1 == Type::TOP ) return Type::TOP;
190 if( t2 == Type::TOP ) return Type::TOP;
191
192 // Either input is ZERO ==> the result is ZERO.
193 // Not valid for floats or doubles since +0.0 * -0.0 --> +0.0
194 int op = Opcode();
195 if( op == Op_MulI || op == Op_AndI || op == Op_MulL || op == Op_AndL ) {
196 const Type *zero = add_id(); // The multiplicative zero
197 if( t1->higher_equal( zero ) ) return zero;
198 if( t2->higher_equal( zero ) ) return zero;
199 }
200
201 // Code pattern on return from a call that returns an __Value. Can
202 // be optimized away if the return value turns out to be an oop.
203 if (op == Op_AndX &&
204 in(1) != nullptr &&
205 in(1)->Opcode() == Op_CastP2X &&
206 in(1)->in(1) != nullptr &&
207 phase->type(in(1)->in(1))->isa_oopptr() &&
208 t2->isa_intptr_t()->_lo >= 0 &&
209 t2->isa_intptr_t()->_hi <= MinObjAlignmentInBytesMask) {
210 return add_id();
211 }
212
213 // Either input is BOTTOM ==> the result is the local BOTTOM
214 if( t1 == Type::BOTTOM || t2 == Type::BOTTOM )
215 return bottom_type();
216
217 return mul_ring(t1,t2); // Local flavor of type multiplication
218 }
219
220 MulNode* MulNode::make(Node* in1, Node* in2, BasicType bt) {
221 switch (bt) {
222 case T_INT:
223 return new MulINode(in1, in2);
224 case T_LONG:
225 return new MulLNode(in1, in2);
226 default:
227 fatal("Not implemented for %s", type2name(bt));
228 }
229 return nullptr;
230 }
231
232 MulNode* MulNode::make_and(Node* in1, Node* in2, BasicType bt) {
924
925 // Masking off sign bits? Dont make them!
926 if (op == Op_RShiftL) {
927 const TypeInt* t12 = phase->type(in1->in(2))->isa_int();
928 if( t12 && t12->is_con() ) { // Shift is by a constant
929 int shift = t12->get_con();
930 shift &= BitsPerJavaLong - 1; // semantics of Java shifts
931 if (shift != 0) {
932 const julong sign_bits_mask = ~(((julong)CONST64(1) << (julong)(BitsPerJavaLong - shift)) -1);
933 // If the AND'ing of the 2 masks has no bits, then only original shifted
934 // bits survive. NO sign-extension bits survive the maskings.
935 if( (sign_bits_mask & mask) == 0 ) {
936 // Use zero-fill shift instead
937 Node *zshift = phase->transform(new URShiftLNode(in1->in(1), in1->in(2)));
938 return new AndLNode(zshift, in(2));
939 }
940 }
941 }
942 }
943
944 // Search for GraphKit::mark_word_test patterns and fold the test if the result is statically known
945 Node* load1 = in(1);
946 Node* load2 = nullptr;
947 if (load1->is_Phi() && phase->type(load1)->isa_long()) {
948 load1 = in(1)->in(1);
949 load2 = in(1)->in(2);
950 }
951 if (load1 != nullptr && load1->is_Load() && phase->type(load1)->isa_long() &&
952 (load2 == nullptr || (load2->is_Load() && phase->type(load2)->isa_long()))) {
953 const TypePtr* adr_t1 = phase->type(load1->in(MemNode::Address))->isa_ptr();
954 const TypePtr* adr_t2 = (load2 != nullptr) ? phase->type(load2->in(MemNode::Address))->isa_ptr() : nullptr;
955 if (adr_t1 != nullptr && adr_t1->offset() == oopDesc::mark_offset_in_bytes() &&
956 (load2 == nullptr || (adr_t2 != nullptr && adr_t2->offset() == in_bytes(Klass::prototype_header_offset())))) {
957 if (mask == markWord::inline_type_pattern) {
958 if (adr_t1->is_inlinetypeptr()) {
959 set_req_X(1, in(2), phase);
960 return this;
961 } else if (!adr_t1->can_be_inline_type()) {
962 set_req_X(1, phase->longcon(0), phase);
963 return this;
964 }
965 } else if (mask == markWord::null_free_array_bit_in_place) {
966 if (adr_t1->is_null_free()) {
967 set_req_X(1, in(2), phase);
968 return this;
969 } else if (adr_t1->is_not_null_free()) {
970 set_req_X(1, phase->longcon(0), phase);
971 return this;
972 }
973 } else if (mask == markWord::flat_array_bit_in_place) {
974 if (adr_t1->is_flat()) {
975 set_req_X(1, in(2), phase);
976 return this;
977 } else if (adr_t1->is_not_flat()) {
978 set_req_X(1, phase->longcon(0), phase);
979 return this;
980 }
981 }
982 }
983 }
984
985 return MulNode::Ideal(phase, can_reshape);
986 }
987
988 LShiftNode* LShiftNode::make(Node* in1, Node* in2, BasicType bt) {
989 switch (bt) {
990 case T_INT:
991 return new LShiftINode(in1, in2);
992 case T_LONG:
993 return new LShiftLNode(in1, in2);
994 default:
995 fatal("Not implemented for %s", type2name(bt));
996 }
997 return nullptr;
998 }
999
1000 // Returns whether the shift amount is constant. If so, sets count.
1001 static bool const_shift_count(PhaseGVN* phase, const Node* shift_node, int* count) {
1002 const TypeInt* tcount = phase->type(shift_node->in(2))->isa_int();
1003 if (tcount != nullptr && tcount->is_con()) {
1004 *count = tcount->get_con();
|