RFR: 8295926: RISC-V: C1: Fix LIRGenerator::do_LibmIntrinsic

Xiaolin Zheng xlinzheng at openjdk.org
Wed Oct 26 07:29:52 UTC 2022


On Wed, 26 Oct 2022 04:57:11 GMT, Xiaolin Zheng <xlinzheng at openjdk.org> wrote:

> The ported logic of LIRGenerator::do_LibmIntrinsic has a correctness problem, which will kill argument registers when the current libm intrinsic's operand is also a libm intrinsic, such as:
> 
> (dpow val1 (dlog val2))
> 
> LIRItem walks operands, so the `value.load_item_force(cc->at(0));` should be moved below after the LIRItem, or the result of `cc->at(0)` would be killed. But we might as well keep aligning AArch64's style to reduce some maintenance work.
> 
> 
> Reproducer:
> 
> 
> public class A {
> 
>     static int count = 0;
> 
>     public static void print(double var) {
>         if (count % 10000 == 0) {
>             System.out.println(var);
>         }
>         count++;
>     }
> 
>     public static void a(double var1, double var2, double var3) {
>         double var4 = Math.pow(var3, Math.log(var1 / var2));
>         print(var4);
>     }
> 
>     public static void main(String[] args) {
> 
>         for (int i = 0; i < 50000; i++) {
>             double var21 = 2.2250738585072014E-308D;
>             double var15 = 1.1102230246251565E-16D;
>             double d1 = 2.0D;
>             A.a(var21, var15, d1);
>         }
> 
>     }
> 
> }
> 
> 
> The right answer is
> 
> 6.461124611136231E-203
> 6.461124611136231E-203
> 6.461124611136231E-203
> 6.461124611136231E-203
> 6.461124611136231E-203
> 
> 
> The current backend gives
> 
> 6.461124611136231E-203
> NaN
> NaN
> NaN
> NaN
> 
> 
> Testing a hotspot tier1~4 on qemu.
> 
> Thanks,
> Xiaolin

The test is copied and modified from Roland's `TestPow2.java` in the same folder.

On x86, aarch64 and riscv with this patch it passes; riscv without this patch shows

interpreter = 2.5355263553695413 c1 = 0.844936682323691 c2 = 2.5355263553695413

and fails.

FYI

python3

>>> math.exp(3.1415926)
23.14069139267437
>>> math.log10(math.exp(3.1415926))
1.3643763305680898
>>> math.log(math.log10(math.exp(3.1415926)))
0.3106974235432832
>>> math.tan(math.log(math.log10(math.exp(3.1415926))))
0.32109666300670675
>>> math.cos(math.tan(math.log(math.log10(math.exp(3.1415926)))))
0.94888987383311
>>> math.sin(math.cos(math.tan(math.log(math.log10(math.exp(3.1415926))))))
0.812769262085064
>>> math.pow(3.1415926, math.sin(math.cos(math.tan(math.log(math.log10(math.exp(3.1415926)))))))
2.5355263553695413


Thanks,
Xiaolin

-------------

PR: https://git.openjdk.org/jdk/pull/10867


More information about the hotspot-compiler-dev mailing list