Skip to content

[Mips] Support llvm.readcyclecounter intrinsic #127553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2025

Conversation

yingopq
Copy link
Contributor

@yingopq yingopq commented Feb 18, 2025

The llvm.readcyclecounter intrinsic can be implemented via the rdhwr $2, $hwr_cc instruction.
$hwr_cc: High-resolution cycle counter. This register provides read access to the coprocessor 0 Count Register.

Fix #106318.

The llvm.readcyclecounter intrinsic can be implemented via the
`rdhwr $2, $hwr_cc` instruction.
$hwr_cc: High-resolution cycle counter. This register provides read
access to the coprocessor 0 Count Register.

Fix llvm#106318.
@wzssyqa wzssyqa merged commit af1e2a3 into llvm:main Feb 18, 2025
9 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Feb 18, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-expensive-checks-debian running on gribozavr4 while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/16/builds/13921

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM :: CodeGen/Mips/readcyclecounter.ll' FAILED ********************
Exit Code: 2

Command Output (stderr):
--
RUN: at line 1: /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc -mtriple=mipsel-linux-gnu -mcpu=mips32r2 < /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/Mips/readcyclecounter.ll | /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/FileCheck /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/Mips/readcyclecounter.ll --check-prefix=MIPSEL
+ /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/FileCheck /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/CodeGen/Mips/readcyclecounter.ll --check-prefix=MIPSEL
+ /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc -mtriple=mipsel-linux-gnu -mcpu=mips32r2

# After Instruction Selection
# Machine code for function test_readcyclecounter: IsSSA, TracksLiveness

bb.0.entry:
  %0:gpr32 = RDHWR $hwr2, 0
  %1:gpr32 = ADDiu $zero, 0
  $v0 = COPY %0:gpr32
  $v1 = COPY %1:gpr32
  RetRA implicit $v0, implicit $v1

# End machine code for function test_readcyclecounter.

*** Bad machine code: Using an undefined physical register ***
- function:    test_readcyclecounter
- basic block: %bb.0 entry (0xad97ee0)
- instruction: %0:gpr32 = RDHWR $hwr2, 0
- operand 1:   $hwr2
LLVM ERROR: Found 1 machine code errors.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc -mtriple=mipsel-linux-gnu -mcpu=mips32r2
1.	Running pass 'Function Pass Manager' on module '<stdin>'.
2.	Running pass 'Verify generated machine code' on function '@test_readcyclecounter'
 #0 0x0000000003873c17 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x3873c17)
 #1 0x00000000038716ce llvm::sys::RunSignalHandlers() (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x38716ce)
 #2 0x00000000038742ca SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007fdd0d1f3140 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x13140)
 #4 0x00007fdd0cd07d51 raise (/lib/x86_64-linux-gnu/libc.so.6+0x38d51)
 #5 0x00007fdd0ccf1537 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22537)
 #6 0x00000000037e3f2a llvm::report_fatal_error(llvm::Twine const&, bool) (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x37e3f2a)
 #7 0x0000000002a60d6d (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x2a60d6d)
 #8 0x0000000002a61ddb (anonymous namespace)::MachineVerifierLegacyPass::runOnMachineFunction(llvm::MachineFunction&) MachineVerifier.cpp:0:0
 #9 0x000000000295e083 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x295e083)
#10 0x0000000002eb3073 llvm::FPPassManager::runOnFunction(llvm::Function&) (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x2eb3073)
#11 0x0000000002eb9aa1 llvm::FPPassManager::runOnModule(llvm::Module&) (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x2eb9aa1)
#12 0x0000000002eb377d llvm::legacy::PassManagerImpl::run(llvm::Module&) (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x2eb377d)
#13 0x00000000008a3afc compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#14 0x00000000008a0ecd main (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x8a0ecd)
#15 0x00007fdd0ccf2d7a __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x23d7a)
#16 0x000000000089fd1a _start (/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llc+0x89fd1a)
FileCheck error: '<stdin>' is empty.
...

@wzssyqa
Copy link
Contributor

wzssyqa commented Feb 18, 2025

Oh, it happens again:

I guess that it means that we need -DLLVM_ENABLE_EXPENSIVE_CHECKS=ON when configure llvm itself to reproduce this problem.

@yingopq
Copy link
Contributor Author

yingopq commented Feb 18, 2025

Oh, it happens again:

I guess that it means that we need -DLLVM_ENABLE_EXPENSIVE_CHECKS=ON when configure llvm itself to reproduce this problem.

OK, I would try. Thanks!

@wzssyqa
Copy link
Contributor

wzssyqa commented Feb 18, 2025

I mark it as XFAIL for now.

#127587

When you fix this problem, please revert it.

yingopq added a commit to yingopq/llvm-project that referenced this pull request Feb 19, 2025
yingopq added a commit to yingopq/llvm-project that referenced this pull request Feb 20, 2025
Fix pr llvm#127553.
x86_64 failed to run readcyclecounter.ll when enable expensive_check,
it would error "Using an undefined physical register".
wzssyqa pushed a commit that referenced this pull request Feb 20, 2025
Fix pr #127553.
x86_64 failed to run readcyclecounter.ll when enable expensive_check,
it would error "Using an undefined physical register".
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Feb 20, 2025
Fix pr llvm/llvm-project#127553.
x86_64 failed to run readcyclecounter.ll when enable expensive_check,
it would error "Using an undefined physical register".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MIPS: Support __builtin_readcyclecounter
3 participants