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 #if defined(IA32)
206 // Can't trust native compilers to properly fold strict double
207 // multiplication with round-to-zero on this platform.
208 if (op == Op_MulD) {
209 return TypeD::DOUBLE;
210 }
211 #endif
212
213 return mul_ring(t1,t2); // Local flavor of type multiplication
214 }
215
216 MulNode* MulNode::make(Node* in1, Node* in2, BasicType bt) {
217 switch (bt) {
218 case T_INT:
219 return new MulINode(in1, in2);
220 case T_LONG:
920
921 // Masking off sign bits? Dont make them!
922 if (op == Op_RShiftL) {
923 const TypeInt* t12 = phase->type(in1->in(2))->isa_int();
924 if( t12 && t12->is_con() ) { // Shift is by a constant
925 int shift = t12->get_con();
926 shift &= BitsPerJavaLong - 1; // semantics of Java shifts
927 if (shift != 0) {
928 const julong sign_bits_mask = ~(((julong)CONST64(1) << (julong)(BitsPerJavaLong - shift)) -1);
929 // If the AND'ing of the 2 masks has no bits, then only original shifted
930 // bits survive. NO sign-extension bits survive the maskings.
931 if( (sign_bits_mask & mask) == 0 ) {
932 // Use zero-fill shift instead
933 Node *zshift = phase->transform(new URShiftLNode(in1->in(1), in1->in(2)));
934 return new AndLNode(zshift, in(2));
935 }
936 }
937 }
938 }
939
940 return MulNode::Ideal(phase, can_reshape);
941 }
942
943 LShiftNode* LShiftNode::make(Node* in1, Node* in2, BasicType bt) {
944 switch (bt) {
945 case T_INT:
946 return new LShiftINode(in1, in2);
947 case T_LONG:
948 return new LShiftLNode(in1, in2);
949 default:
950 fatal("Not implemented for %s", type2name(bt));
951 }
952 return nullptr;
953 }
954
955 // Returns whether the shift amount is constant. If so, sets count.
956 static bool const_shift_count(PhaseGVN* phase, const Node* shift_node, int* count) {
957 const TypeInt* tcount = phase->type(shift_node->in(2))->isa_int();
958 if (tcount != nullptr && tcount->is_con()) {
959 *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 #if defined(IA32)
218 // Can't trust native compilers to properly fold strict double
219 // multiplication with round-to-zero on this platform.
220 if (op == Op_MulD) {
221 return TypeD::DOUBLE;
222 }
223 #endif
224
225 return mul_ring(t1,t2); // Local flavor of type multiplication
226 }
227
228 MulNode* MulNode::make(Node* in1, Node* in2, BasicType bt) {
229 switch (bt) {
230 case T_INT:
231 return new MulINode(in1, in2);
232 case T_LONG:
932
933 // Masking off sign bits? Dont make them!
934 if (op == Op_RShiftL) {
935 const TypeInt* t12 = phase->type(in1->in(2))->isa_int();
936 if( t12 && t12->is_con() ) { // Shift is by a constant
937 int shift = t12->get_con();
938 shift &= BitsPerJavaLong - 1; // semantics of Java shifts
939 if (shift != 0) {
940 const julong sign_bits_mask = ~(((julong)CONST64(1) << (julong)(BitsPerJavaLong - shift)) -1);
941 // If the AND'ing of the 2 masks has no bits, then only original shifted
942 // bits survive. NO sign-extension bits survive the maskings.
943 if( (sign_bits_mask & mask) == 0 ) {
944 // Use zero-fill shift instead
945 Node *zshift = phase->transform(new URShiftLNode(in1->in(1), in1->in(2)));
946 return new AndLNode(zshift, in(2));
947 }
948 }
949 }
950 }
951
952 // Search for GraphKit::mark_word_test patterns and fold the test if the result is statically known
953 Node* load1 = in(1);
954 Node* load2 = nullptr;
955 if (load1->is_Phi() && phase->type(load1)->isa_long()) {
956 load1 = in(1)->in(1);
957 load2 = in(1)->in(2);
958 }
959 if (load1 != nullptr && load1->is_Load() && phase->type(load1)->isa_long() &&
960 (load2 == nullptr || (load2->is_Load() && phase->type(load2)->isa_long()))) {
961 const TypePtr* adr_t1 = phase->type(load1->in(MemNode::Address))->isa_ptr();
962 const TypePtr* adr_t2 = (load2 != nullptr) ? phase->type(load2->in(MemNode::Address))->isa_ptr() : nullptr;
963 if (adr_t1 != nullptr && adr_t1->offset() == oopDesc::mark_offset_in_bytes() &&
964 (load2 == nullptr || (adr_t2 != nullptr && adr_t2->offset() == in_bytes(Klass::prototype_header_offset())))) {
965 if (mask == markWord::inline_type_pattern) {
966 if (adr_t1->is_inlinetypeptr()) {
967 set_req_X(1, in(2), phase);
968 return this;
969 } else if (!adr_t1->can_be_inline_type()) {
970 set_req_X(1, phase->longcon(0), phase);
971 return this;
972 }
973 } else if (mask == markWord::null_free_array_bit_in_place) {
974 if (adr_t1->is_null_free()) {
975 set_req_X(1, in(2), phase);
976 return this;
977 } else if (adr_t1->is_not_null_free()) {
978 set_req_X(1, phase->longcon(0), phase);
979 return this;
980 }
981 } else if (mask == markWord::flat_array_bit_in_place) {
982 if (adr_t1->is_flat()) {
983 set_req_X(1, in(2), phase);
984 return this;
985 } else if (adr_t1->is_not_flat()) {
986 set_req_X(1, phase->longcon(0), phase);
987 return this;
988 }
989 }
990 }
991 }
992
993 return MulNode::Ideal(phase, can_reshape);
994 }
995
996 LShiftNode* LShiftNode::make(Node* in1, Node* in2, BasicType bt) {
997 switch (bt) {
998 case T_INT:
999 return new LShiftINode(in1, in2);
1000 case T_LONG:
1001 return new LShiftLNode(in1, in2);
1002 default:
1003 fatal("Not implemented for %s", type2name(bt));
1004 }
1005 return nullptr;
1006 }
1007
1008 // Returns whether the shift amount is constant. If so, sets count.
1009 static bool const_shift_count(PhaseGVN* phase, const Node* shift_node, int* count) {
1010 const TypeInt* tcount = phase->type(shift_node->in(2))->isa_int();
1011 if (tcount != nullptr && tcount->is_con()) {
1012 *count = tcount->get_con();
|