src/hotspot/share/opto/mathexactnode.cpp
author rbackman
Thu, 18 Jan 2018 19:21:11 +0100
changeset 48704 4162f740b7bd
parent 47216 71c04702a3d5
permissions -rw-r--r--
8191915: JCK tests produce incorrect results with C2 Reviewed-by: thartmann, vlivanov, goetz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20289
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
     1
/*
48704
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
     2
 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
20289
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
     4
 *
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
     7
 * published by the Free Software Foundation.
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
     8
 *
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    13
 * accompanied this code).
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    14
 *
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    18
 *
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    21
 * questions.
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    22
 *
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    23
 */
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    24
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    25
#include "precompiled.hpp"
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    26
#include "memory/allocation.inline.hpp"
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    27
#include "opto/addnode.hpp"
20715
be1135dc1406 8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents: 20289
diff changeset
    28
#include "opto/cfgnode.hpp"
20289
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    29
#include "opto/machnode.hpp"
20715
be1135dc1406 8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
rbackman
parents: 20289
diff changeset
    30
#include "opto/matcher.hpp"
20289
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    31
#include "opto/mathexactnode.hpp"
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    32
#include "opto/subnode.hpp"
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    33
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    34
template <typename OverflowOp>
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    35
class AddHelper {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    36
public:
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    37
  typedef typename OverflowOp::TypeClass TypeClass;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    38
  typedef typename TypeClass::NativeType NativeType;
20289
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    39
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    40
  static bool will_overflow(NativeType value1, NativeType value2) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    41
    NativeType result = value1 + value2;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    42
    // Hacker's Delight 2-12 Overflow if both arguments have the opposite sign of the result
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    43
    if (((value1 ^ result) & (value2 ^ result)) >= 0) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    44
      return false;
20289
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    45
    }
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    46
    return true;
20289
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    47
  }
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    48
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    49
  static bool can_overflow(const Type* type1, const Type* type2) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    50
    if (type1 == TypeClass::ZERO || type2 == TypeClass::ZERO) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    51
      return false;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    52
    }
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    53
    return true;
20289
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    54
  }
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    55
};
20289
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents:
diff changeset
    56
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    57
template <typename OverflowOp>
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    58
class SubHelper {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    59
public:
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    60
  typedef typename OverflowOp::TypeClass TypeClass;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    61
  typedef typename TypeClass::NativeType NativeType;
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
    62
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    63
  static bool will_overflow(NativeType value1, NativeType value2) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    64
    NativeType result = value1 - value2;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    65
    // hacker's delight 2-12 overflow iff the arguments have different signs and
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    66
    // the sign of the result is different than the sign of arg1
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    67
    if (((value1 ^ value2) & (value1 ^ result)) >= 0) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    68
      return false;
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
    69
    }
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    70
    return true;
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
    71
  }
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
    72
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    73
  static bool can_overflow(const Type* type1, const Type* type2) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    74
    if (type2 == TypeClass::ZERO) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    75
      return false;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    76
    }
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    77
    return true;
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
    78
  }
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    79
};
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
    80
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    81
template <typename OverflowOp>
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    82
class MulHelper {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    83
public:
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    84
  typedef typename OverflowOp::TypeClass TypeClass;
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
    85
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    86
  static bool can_overflow(const Type* type1, const Type* type2) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    87
    if (type1 == TypeClass::ZERO || type2 == TypeClass::ZERO) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    88
      return false;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    89
    } else if (type1 == TypeClass::ONE || type2 == TypeClass::ONE) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    90
      return false;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    91
    }
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    92
    return true;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    93
  }
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    94
};
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
    95
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    96
bool OverflowAddINode::will_overflow(jint v1, jint v2) const {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
    97
  return AddHelper<OverflowAddINode>::will_overflow(v1, v2);
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
    98
}
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
    99
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   100
bool OverflowSubINode::will_overflow(jint v1, jint v2) const {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   101
  return SubHelper<OverflowSubINode>::will_overflow(v1, v2);
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
   102
}
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
   103
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   104
bool OverflowMulINode::will_overflow(jint v1, jint v2) const {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   105
    jlong result = (jlong) v1 * (jlong) v2;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   106
    if ((jint) result == result) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   107
      return false;
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
   108
    }
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   109
    return true;
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
   110
}
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
   111
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   112
bool OverflowAddLNode::will_overflow(jlong v1, jlong v2) const {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   113
  return AddHelper<OverflowAddLNode>::will_overflow(v1, v2);
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
   114
}
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
   115
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   116
bool OverflowSubLNode::will_overflow(jlong v1, jlong v2) const {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   117
  return SubHelper<OverflowSubLNode>::will_overflow(v1, v2);
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   118
}
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
   119
48704
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   120
bool OverflowMulLNode::is_overflow(jlong val1, jlong val2) {
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   121
    // x * { 0, 1 } will never overflow. Even for x = min_jlong
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   122
    if (val1 == 0 || val2 == 0 || val1 == 1 || val2 == 1) {
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   123
      return false;
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   124
    }
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
   125
48704
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   126
    // x * min_jlong for x not in { 0, 1 } overflows
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   127
    // even -1 as -1 * min_jlong is an overflow
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   128
    if (val1 == min_jlong || val2 == min_jlong) {
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   129
      return true;
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
   130
    }
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
   131
48704
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   132
    // if (x * y) / y == x there is no overflow
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   133
    //
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   134
    // the multiplication here is done as unsigned to avoid undefined behaviour which
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   135
    // can be used by the compiler to assume that the check further down (result / val2 != val1)
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   136
    // is always false and breaks the overflow check
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   137
    julong v1 = (julong) val1;
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   138
    julong v2 = (julong) val2;
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   139
    julong tmp = v1 * v2;
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   140
    jlong result = (jlong) tmp;
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   141
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   142
    if (result / val2 != val1) {
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   143
      return true;
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   144
    }
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   145
4162f740b7bd 8191915: JCK tests produce incorrect results with C2
rbackman
parents: 47216
diff changeset
   146
    return false;
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   147
}
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   148
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   149
bool OverflowAddINode::can_overflow(const Type* t1, const Type* t2) const {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   150
  return AddHelper<OverflowAddINode>::can_overflow(t1, t2);
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   151
}
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   152
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   153
bool OverflowSubINode::can_overflow(const Type* t1, const Type* t2) const {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   154
  if (in(1) == in(2)) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   155
    return false;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   156
  }
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   157
  return SubHelper<OverflowSubINode>::can_overflow(t1, t2);
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   158
}
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   159
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   160
bool OverflowMulINode::can_overflow(const Type* t1, const Type* t2) const {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   161
  return MulHelper<OverflowMulINode>::can_overflow(t1, t2);
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   162
}
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   163
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   164
bool OverflowAddLNode::can_overflow(const Type* t1, const Type* t2) const {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   165
  return AddHelper<OverflowAddLNode>::can_overflow(t1, t2);
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   166
}
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   167
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   168
bool OverflowSubLNode::can_overflow(const Type* t1, const Type* t2) const {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   169
  if (in(1) == in(2)) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   170
    return false;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   171
  }
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   172
  return SubHelper<OverflowSubLNode>::can_overflow(t1, t2);
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   173
}
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   174
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   175
bool OverflowMulLNode::can_overflow(const Type* t1, const Type* t2) const {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   176
  return MulHelper<OverflowMulLNode>::can_overflow(t1, t2);
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   177
}
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   178
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   179
const Type* OverflowNode::sub(const Type* t1, const Type* t2) const {
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 25930
diff changeset
   180
  fatal("sub() should not be called for '%s'", NodeClassNames[this->Opcode()]);
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   181
  return TypeInt::CC;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   182
}
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   183
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   184
template <typename OverflowOp>
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   185
struct IdealHelper {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   186
  typedef typename OverflowOp::TypeClass TypeClass; // TypeInt, TypeLong
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   187
  typedef typename TypeClass::NativeType NativeType;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   188
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   189
  static Node* Ideal(const OverflowOp* node, PhaseGVN* phase, bool can_reshape) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   190
    Node* arg1 = node->in(1);
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   191
    Node* arg2 = node->in(2);
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   192
    const Type* type1 = phase->type(arg1);
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   193
    const Type* type2 = phase->type(arg2);
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   194
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   195
    if (type1 == NULL || type2 == NULL) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   196
      return NULL;
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
   197
    }
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
   198
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   199
    if (type1 != Type::TOP && type1->singleton() &&
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   200
        type2 != Type::TOP && type2->singleton()) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   201
      NativeType val1 = TypeClass::as_self(type1)->get_con();
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   202
      NativeType val2 = TypeClass::as_self(type2)->get_con();
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   203
      if (node->will_overflow(val1, val2) == false) {
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 22911
diff changeset
   204
        Node* con_result = ConINode::make(0);
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   205
        return con_result;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   206
      }
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   207
      return NULL;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   208
    }
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   209
    return NULL;
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
   210
  }
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
   211
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   212
  static const Type* Value(const OverflowOp* node, PhaseTransform* phase) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   213
    const Type *t1 = phase->type( node->in(1) );
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   214
    const Type *t2 = phase->type( node->in(2) );
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   215
    if( t1 == Type::TOP ) return Type::TOP;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   216
    if( t2 == Type::TOP ) return Type::TOP;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   217
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   218
    const TypeClass* i1 = TypeClass::as_self(t1);
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   219
    const TypeClass* i2 = TypeClass::as_self(t2);
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   220
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   221
    if (i1 == NULL || i2 == NULL) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   222
      return TypeInt::CC;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   223
    }
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
   224
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   225
    if (t1->singleton() && t2->singleton()) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   226
      NativeType val1 = i1->get_con();
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   227
      NativeType val2 = i2->get_con();
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   228
      if (node->will_overflow(val1, val2)) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   229
        return TypeInt::CC;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   230
      }
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   231
      return TypeInt::ZERO;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   232
    } else if (i1 != TypeClass::TYPE_DOMAIN && i2 != TypeClass::TYPE_DOMAIN) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   233
      if (node->will_overflow(i1->_lo, i2->_lo)) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   234
        return TypeInt::CC;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   235
      } else if (node->will_overflow(i1->_lo, i2->_hi)) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   236
        return TypeInt::CC;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   237
      } else if (node->will_overflow(i1->_hi, i2->_lo)) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   238
        return TypeInt::CC;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   239
      } else if (node->will_overflow(i1->_hi, i2->_hi)) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   240
        return TypeInt::CC;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   241
      }
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   242
      return TypeInt::ZERO;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   243
    }
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
   244
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   245
    if (!node->can_overflow(t1, t2)) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   246
      return TypeInt::ZERO;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   247
    }
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   248
    return TypeInt::CC;
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
   249
  }
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   250
};
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
   251
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   252
Node* OverflowINode::Ideal(PhaseGVN* phase, bool can_reshape) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   253
  return IdealHelper<OverflowINode>::Ideal(this, phase, can_reshape);
21105
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
   254
}
47618ee96ed5 8026844: Various Math functions needs intrinsification
rbackman
parents: 20715
diff changeset
   255
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   256
Node* OverflowLNode::Ideal(PhaseGVN* phase, bool can_reshape) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   257
  return IdealHelper<OverflowLNode>::Ideal(this, phase, can_reshape);
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   258
}
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   259
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 33105
diff changeset
   260
const Type* OverflowINode::Value(PhaseGVN* phase) const {
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   261
  return IdealHelper<OverflowINode>::Value(this, phase);
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   262
}
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   263
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 33105
diff changeset
   264
const Type* OverflowLNode::Value(PhaseGVN* phase) const {
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   265
  return IdealHelper<OverflowLNode>::Value(this, phase);
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   266
}
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 21105
diff changeset
   267