Skip to content

[LoongArch64] Fix the risk of sign-extension in CodeGen::genIntCastOverflowCheck() with CHECK_SMALL_INT_RANGE signed to signed cast case. - #130546

Merged
jakobbotsch merged 3 commits into
dotnet:mainfrom
LuckyXu-HF:main-LA64
Jul 13, 2026
Merged

jakobbotsch merged 3 commits into
dotnet:mainfrom
LuckyXu-HF:main-LA64

Conversation

@LuckyXu-HF

Copy link
Copy Markdown
Contributor
  • Fix the random failed in Release libs.tests: System.Runtime.Numerics.Tests.
  • Optimize instructions in CodeGen::genCodeForCompare() with some sub-divide case.

…erflowCheck() with `CHECK_SMALL_INT_RANGE signed to signed cast` case.

* Fix the random failed in Release libs.tests: System.Runtime.Numerics.Tests.
* Optimize CodeGen::genCodeForCompare() with some sub-divide case.
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 11, 2026
@LuckyXu-HF

Copy link
Copy Markdown
Contributor Author

The release libs.tests System.Runtime.Numerics.Tests will hit a random failure with about 10% probability on LA64, such as the System.Numerics.Tests.op_rightshiftTest.RunSmallTests:

random failed of System.Numerics.Tests.op_rightshiftTest.RunSmallTests
  Discovering: System.Runtime.Numerics.Tests (method display = ClassAndMethod, method display options = None)
  Discovered:  System.Runtime.Numerics.Tests (found 641 of 654 test cases)
  Starting:    System.Runtime.Numerics.Tests (parallel test collections = on [8 threads], stop on fail = off)
Failed to parse string 
    System.Numerics.Tests.op_rightshiftTest.RunSmallTests [FAIL]
      System.OverflowException : Arithmetic operation resulted in an overflow.
      Stack Trace:
        /data/xuliangyu/main/runtime/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs(2196,0): at System.Numerics.BigInteger.op_Explicit(BigInteger value)
        /data/xuliangyu/main/runtime/src/libraries/System.Runtime.Numerics/tests/BigInteger/MyBigInt.cs(704,0): at System.Numerics.Tests.MyBigIntImp.ShiftLeft(List`1 bytes1, List`1 bytes2)
        /data/xuliangyu/main/runtime/src/libraries/System.Runtime.Numerics/tests/BigInteger/MyBigInt.cs(110,0): at System.Numerics.Tests.MyBigIntImp.DoBinaryOperatorMine(BigInteger num1, BigInteger num2, String op, BigInteger& num3)
        /data/xuliangyu/main/runtime/src/libraries/System.Runtime.Numerics/tests/BigInteger/stackcalculator.cs(71,0): at System.Numerics.Tests.StackCalc.DoNextOperation()
        /data/xuliangyu/main/runtime/src/libraries/System.Runtime.Numerics/tests/BigInteger/op_rightshift.cs(226,0): at System.Numerics.Tests.op_rightshiftTestBase.VerifyRightShiftString(String opstring)
        /data/xuliangyu/main/runtime/src/libraries/System.Runtime.Numerics/tests/BigInteger/op_rightshift.cs(214,0): at System.Numerics.Tests.op_rightshiftTestBase.RunSmallTests()
           at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
           at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
        /data/xuliangyu/main/runtime/src/coreclr/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.CoreCLR.cs(37,0): at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
        /data/xuliangyu/main/runtime/src/libraries/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs(134,0): at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
  Finished:    System.Runtime.Numerics.Tests
=== TEST EXECUTION SUMMARY ===
   System.Runtime.Numerics.Tests  Total: 3033, Errors: 0, Failed: 1, Skipped: 0, Time: 32.050s

This commit is mainly to fix the above issue, based on this fix the test passed 100 times with 0 failed.

Comment thread src/coreclr/jit/codegenloongarch64.cpp
@LuckyXu-HF

Copy link
Copy Markdown
Contributor Author

@shushanhf @jakobbotsch Could you please review this PR? Thanks.

@shushanhf shushanhf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!
We tested it OK on our local LA64-machine.
@jakobbotsch Could you give some advices ? thanks

@jakobbotsch
jakobbotsch merged commit e7f7027 into dotnet:main Jul 13, 2026
140 checks passed
@LuckyXu-HF
LuckyXu-HF deleted the main-LA64 branch July 14, 2026 07:41
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 14, 2026
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
…erflowCheck() with `CHECK_SMALL_INT_RANGE signed to signed cast` case. (#130546)

* Fix the random failed in Release libs.tests:
System.Runtime.Numerics.Tests.
* Optimize instructions in CodeGen::genCodeForCompare() with some
sub-divide case.
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-loongarch64 area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants