Skip to content

cpu-o3: fix pc nullptr for storeDataUop#485

Open
Rrraaaeee wants to merge 1 commit into
OpenXiangShan:xs-devfrom
Rrraaaeee:xs-dev
Open

cpu-o3: fix pc nullptr for storeDataUop#485
Rrraaaeee wants to merge 1 commit into
OpenXiangShan:xs-devfrom
Rrraaaeee:xs-dev

Conversation

@Rrraaaeee

@Rrraaaeee Rrraaaeee commented Jul 14, 2025

Copy link
Copy Markdown
Contributor

Description:
gem5 encounters segmentation fault when specifying--debug-flags=IEW

Command:
${GEM5_HOME}/build/RISCV/gem5.opt --debug-flags=IEW ./configs/example/xiangshan.py --difftest-ref-so=${NEMU_HOME}/build/riscv64-nemu-interpreter-so --num-cpus=1 --raw-cpt --generic-rv-cpt=${NOOP_HOME}/ready-to-run/linux.bin

Cause:
When creating storeDataUop, the pc and next_pc arguments are not passed to the DynInst constructor, causing them to be nullptrs.

Fix:
Initialize pc and next_pc with those from the storeAddrUop.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced register initialization for vector memory instruction processing to ensure proper register index setup.

✏️ Tip: You can customize this high-level summary in your review settings.

@tastynoob

tastynoob commented Jul 14, 2025

Copy link
Copy Markdown
Collaborator

This pr is unreasonable, std uop shoud not read the pc

@tastynoob

tastynoob commented Jul 14, 2025

Copy link
Copy Markdown
Collaborator

You should avoid reading the std uop pc

@XiangShanRobot

Copy link
Copy Markdown

[Generated by GEM5 Performance Robot]
commit: e596703
workflow: gem5 Simple RVV Performance Test (Ideal BTB)

Ideal BTB Performance

Overall Score

PR Master Diff(%)
Score 19.39 19.16 +1.21 🟢

@XiangShanRobot

Copy link
Copy Markdown

[Generated by GEM5 Performance Robot]
commit: e596703
workflow: gem5 Performance Test

Standard Performance

Overall Score

PR Master Diff(%)
Score 16.17 16.17 0.00

@XiangShanRobot

Copy link
Copy Markdown

[Generated by GEM5 Performance Robot]
commit: e596703
workflow: gem5 Ideal BTB Performance Test

Ideal BTB Performance

Overall Score

PR Master Diff(%)
Score 19.77 19.50 +1.38 🟢

@coderabbitai

coderabbitai Bot commented Jan 9, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Added initialization hook calls in VlWholeConstructor constructors to execute the set_reg_idx_arr sequence. The change inserts explicit calls to set up registration indices in two constructor locations, with no control-flow modifications beyond this setup step invocation.

Changes

Cohort / File(s) Summary
Vector Memory Initialization
src/arch/riscv/isa/vector/base/vector_mem.temp.isa
Added %(set_reg_idx_arr)s initialization hook calls in VlWholeConstructor constructors to explicitly invoke register index array setup before NFIELDS initialization (+2 lines)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • happy-lx
  • tastynoob

Poem

🐰 Two tiny hooks now planted with care,
Register indices setup everywhere,
Constructors initialized, clean and bright,
VlWhole now starts with everything right! 🎯

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title mentions fixing pc nullptr for storeDataUop, but the actual code change initializes a register index array in VlWholeConstructor, which is unrelated to storeDataUop or pc handling. Update the title to reflect the actual change: something like 'fix uninitialized reg arr for VlWhole staticInst type' which matches the commit message and the actual code modification.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @src/arch/riscv/isa/vector/base/vector_mem.temp.isa:
- Around line 426-427: The VlWholeConstructor macro was changed to include
%(set_reg_idx_arr)s; making it inconsistent with other macro constructors and
its store counterpart VsWholeConstructor; revert this addition from
VlWholeConstructor (or alternatively add the same %(set_reg_idx_arr)s; to all
other macro constructors including VsWholeConstructor, VleConstructor,
VleffConstructor, VseConstructor, VlStrideConstructor, VsStrideConstructor,
VlIndexConstructor, VlmConstructor, VsmConstructor, VsIndexConstructor) so
macro-level constructors remain consistent and only micro-level constructors
(e.g., VlWholeMicro and other micro ops) perform register-array initialization.
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e46fe3b and 51174fb.

📒 Files selected for processing (1)
  • src/arch/riscv/isa/vector/base/vector_mem.temp.isa
🔇 Additional comments (1)
src/arch/riscv/isa/vector/base/vector_mem.temp.isa (1)

426-427: Clarify the discrepancy between the PR title and the actual code changes.

The PR title states the fix is for "pc nullptr for storeDataUop," but the code adds register index array initialization to VlWholeConstructor. While uninitialized register arrays in VlWhole are a known issue in XiangShan, this suggests either:

  1. The PR title is incorrect/outdated
  2. Separate fixes are bundled together, with storeDataUop changes located elsewhere

Additionally, VsWholeConstructor (the store equivalent, lines 1186–1208) lacks this same initialization. If this fix is necessary for VlWhole, clarify whether VsWhole should receive it as well, or explain why store operations don't require the same initialization.

Comment on lines +426 to +427
%(set_reg_idx_arr)s;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's understand the file structure and find all macro constructors
cat -n src/arch/riscv/isa/vector/base/vector_mem.temp.isa | head -50

Repository: OpenXiangShan/GEM5

Length of output: 1383


🏁 Script executed:

# Check the VlWholeConstructor around line 426-427
sed -n '400,450p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | cat -n

Repository: OpenXiangShan/GEM5

Length of output: 1598


🏁 Script executed:

# Check VsWholeConstructor (lines 1186-1208)
sed -n '1180,1210p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | cat -n

Repository: OpenXiangShan/GEM5

Length of output: 1055


🏁 Script executed:

# Search for all macro-level constructors in the file
rg -n 'def constructor.*:' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | head -20

Repository: OpenXiangShan/GEM5

Length of output: 44


🏁 Script executed:

# Search for set_reg_idx_arr across the file to see where it appears
rg -n 'set_reg_idx_arr' src/arch/riscv/isa/vector/base/vector_mem.temp.isa

Repository: OpenXiangShan/GEM5

Length of output: 458


🏁 Script executed:

# Find all constructor definitions to map line numbers to constructors
rg -n 'def template.*Constructor|def template.*Declare' src/arch/riscv/isa/vector/base/vector_mem.temp.isa

Repository: OpenXiangShan/GEM5

Length of output: 987


🏁 Script executed:

# Get context around each set_reg_idx_arr occurrence to identify the constructor
for line in 117 351 426 459 560 688 821 1051 1163 1221 1288 1366; do
  echo "=== Line $line ==="
  sed -n "$((line-10)),$((line+2))p" src/arch/riscv/isa/vector/base/vector_mem.temp.isa | grep -E 'def template|class|::|%(class_name)s::' | head -3
done

Repository: OpenXiangShan/GEM5

Length of output: 2633


🏁 Script executed:

# More detailed context for the key comparisons
echo "=== Around line 426 (VlWholeConstructor claim) ==="
sed -n '415,435p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | cat -n

echo -e "\n=== Around line 1221 (likely near VsWholeConstructor) ==="
sed -n '1210,1230p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | cat -n

Repository: OpenXiangShan/GEM5

Length of output: 1623


🏁 Script executed:

# Let me verify which macro constructors have set_reg_idx_arr
# Check each macro constructor template

echo "=== VleConstructor (starts at line 45) ==="
sed -n '45,105p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | grep -n 'set_reg_idx_arr\|^%%'

echo -e "\n=== VleffConstructor (starts at line 310) ==="
sed -n '310,338p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | grep -n 'set_reg_idx_arr\|^%%'

echo -e "\n=== VlStrideConstructor (starts at line 504) ==="
sed -n '504,547p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | grep -n 'set_reg_idx_arr\|^%%'

echo -e "\n=== VlIndexConstructor (starts at line 623) ==="
sed -n '623,674p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | grep -n 'set_reg_idx_arr\|^%%'

echo -e "\n=== VseConstructor (starts at line 758) ==="
sed -n '758,809p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | grep -n 'set_reg_idx_arr\|^%%'

echo -e "\n=== VlmConstructor (starts at line 1003) ==="
sed -n '1003,1039p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | grep -n 'set_reg_idx_arr\|^%%'

echo -e "\n=== VsmConstructor (starts at line 1116) ==="
sed -n '1116,1151p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | grep -n 'set_reg_idx_arr\|^%%'

echo -e "\n=== VsWholeConstructor (starts at line 1186) ==="
sed -n '1186,1209p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | grep -n 'set_reg_idx_arr\|^%%'

echo -e "\n=== VsStrideConstructor (starts at line 1239) ==="
sed -n '1239,1275p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | grep -n 'set_reg_idx_arr\|^%%'

echo -e "\n=== VsIndexConstructor (starts at line 1311) ==="
sed -n '1311,1352p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | grep -n 'set_reg_idx_arr\|^%%'

Repository: OpenXiangShan/GEM5

Length of output: 538


🏁 Script executed:

# Let's directly check the content of each macro constructor more carefully
echo "=== VlWholeConstructor (lines 421-447) ==="
sed -n '421,447p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | cat -n

echo -e "\n=== VsWholeConstructor (lines 1186-1209) ==="
sed -n '1186,1209p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | cat -n

Repository: OpenXiangShan/GEM5

Length of output: 1820


🏁 Script executed:

# Check a few other macro constructors
echo "=== VleConstructor (lines 45-105) ==="
sed -n '45,105p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | cat -n

echo -e "\n=== VseConstructor (lines 758-809) ==="
sed -n '758,809p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | cat -n

Repository: OpenXiangShan/GEM5

Length of output: 4822


🏁 Script executed:

# Let me check the remaining macro constructors to be thorough
echo "=== VleffConstructor (lines 310-338) ==="
sed -n '310,338p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | cat -n

echo -e "\n=== VlStrideConstructor (lines 504-547) ==="
sed -n '504,547p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | cat -n

echo -e "\n=== VlIndexConstructor (lines 623-674) ==="
sed -n '623,674p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | cat -n

echo -e "\n=== VlmConstructor (lines 1003-1039) ==="
sed -n '1003,1039p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | cat -n

Repository: OpenXiangShan/GEM5

Length of output: 6280


🏁 Script executed:

echo "=== VsmConstructor (lines 1116-1151) ==="
sed -n '1116,1151p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | cat -n

echo -e "\n=== VsStrideConstructor (lines 1239-1275) ==="
sed -n '1239,1275p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | cat -n

echo -e "\n=== VsIndexConstructor (lines 1311-1352) ==="
sed -n '1311,1352p' src/arch/riscv/isa/vector/base/vector_mem.temp.isa | cat -n

Repository: OpenXiangShan/GEM5

Length of output: 4639


Pattern inconsistency: Why only VlWholeConstructor among macro constructors?

This change adds %(set_reg_idx_arr)s; initialization to the VlWholeConstructor macro-level constructor, making it the only macro constructor with this initialization. Verified observations:

  1. VsWholeConstructor (lines 1186-1209, the store equivalent) lacks this initialization
  2. All other macro constructors (VleConstructor, VleffConstructor, VseConstructor, VlStrideConstructor, VsStrideConstructor, VlIndexConstructor, VlmConstructor, VsmConstructor, VsIndexConstructor) lack this initialization
  3. All micro-level constructors have this initialization (e.g., line 459 for VlWholeMicro)

Since macro constructors create micro-ops but don't directly perform register operations, clarify:

  • Why does the macro-level constructor need register array initialization when no other macro constructor does?
  • Why is VlWholeConstructor treated differently from its store counterpart VsWholeConstructor?
🤖 Prompt for AI Agents
In @src/arch/riscv/isa/vector/base/vector_mem.temp.isa around lines 426 - 427,
The VlWholeConstructor macro was changed to include %(set_reg_idx_arr)s; making
it inconsistent with other macro constructors and its store counterpart
VsWholeConstructor; revert this addition from VlWholeConstructor (or
alternatively add the same %(set_reg_idx_arr)s; to all other macro constructors
including VsWholeConstructor, VleConstructor, VleffConstructor, VseConstructor,
VlStrideConstructor, VsStrideConstructor, VlIndexConstructor, VlmConstructor,
VsmConstructor, VsIndexConstructor) so macro-level constructors remain
consistent and only micro-level constructors (e.g., VlWholeMicro and other micro
ops) perform register-array initialization.

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.

3 participants