Skip to content

Conversation

@zyw-bot
Copy link
Collaborator

@zyw-bot zyw-bot commented Jul 7, 2025

Link: llvm/llvm-project#147319
Requested by: @nikic

@github-actions github-actions bot mentioned this pull request Jul 7, 2025
@zyw-bot
Copy link
Collaborator Author

zyw-bot commented Jul 7, 2025

Diff mode

runner: ariselab-64c-docker
baseline: llvm/llvm-project@6aa33ee
patch: llvm/llvm-project#147319
sha256: 87c10ecb4ddeb8d826a3c4c1a229e2554a39abaaa65cc5dbaa8ddf0b1d615b0e
commit: 5a844f0

4 files changed, 253 insertions(+), 253 deletions(-)

Improvements:
  div-rem-pairs.NumPairs 56270 -> 56272 +0.00%
  gvn.NumGVNInstr 159853 -> 159855 +0.00%
  gvn.NumGVNPRE 159853 -> 159855 +0.00%
  last-run-tracking.NumSkippedPasses 51937576 -> 51937578 +0.00%
Regressions:
  correlated-value-propagation.NumMulNSW 79749 -> 79746 -0.00%
  correlated-value-propagation.NumMulNW 143179 -> 143176 -0.00%
  reassociate.NumChanged 5220763 -> 5220733 -0.00%
  correlated-value-propagation.NumNSW 656749 -> 656746 -0.00%
  correlated-value-propagation.NumNW 1076762 -> 1076759 -0.00%
  instcombine.NumDeadInst 44233665 -> 44233661 -0.00%
  instcombine.NumCombined 130200113 -> 130200105 -0.00%
  instcombine.NumOneIteration 65790589 -> 65790587 -0.00%
  instcombine.NumWorklistIterations 65790589 -> 65790587 -0.00%

51 51 bench/deku-rs/optimized/a0kcfjeveelfut0w9ii1hqsyf.ll
2 2 bench/ncnn/optimized/lstm_x86_avx512.ll

@github-actions
Copy link
Contributor

github-actions bot commented Jul 7, 2025

The patch modifies LLVM IR in several functions related to bit manipulation and memory layout calculations, primarily within the bitvec crate used by Rust code (e.g., BitVec). Below is a high-level summary of up to 5 major changes:

  1. Optimized Bit-to-Element Conversion Logic
    Multiple instances replace a pattern:

    %val = lshr i64 %bits, 3
    %mul = mul i64 %val, -7
    %sum = add i64 %mul, %bits

    with:

    %rem = and i64 %bits, 7
    %sum = add nuw nsw i64 %val, %rem

    This change replaces a negative multiplication trick with a more readable and semantically correct bitwise AND followed by addition, computing (bits + 7) / 8 or equivalent byte count logic.

  2. Phi Node Adjustments in Control Flow Merge Blocks
    PHI nodes in merge blocks were updated to reflect new variable names or value sources due to earlier logic changes. These are mostly mechanical updates ensuring correctness after replacing arithmetic idioms.

  3. Simplified Arithmetic Expressions in Memory Layout Computation
    Several local computations involving shifts, masks, and adds were simplified for better readability and maintainability. These align with modern LLVM’s preferred patterns for pointer and size calculations.

  4. Minor Cleanup Around Tail Calls and Local Variable Initialization
    Some redundant loads and stores were removed or reordered around tail calls, improving clarity without changing semantics.

  5. Improved Use of NUW/NSW Flags on Add Instructions
    The patch adds nuw and nsw flags where appropriate to indicate that additions do not wrap, helping enable further optimizations by informing LLVM about overflow behavior.

Summary

This patch replaces an outdated arithmetic trick (x * -7 + y) with a clearer and safer equivalent using %x & 7 followed by addition, improving both readability and optimization potential. It also adjusts control flow PHIs and improves metadata around integer overflow behavior.

model: qwen-plus-latest
CompletionUsage(completion_tokens=441, prompt_tokens=9828, total_tokens=10269, completion_tokens_details=None, prompt_tokens_details=None)

@nikic
Copy link

nikic commented Jul 7, 2025

/add-label reviewed
/close

@github-actions github-actions bot closed this Jul 7, 2025
@dtcxzyw dtcxzyw deleted the test-run16121890698 branch July 10, 2025 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants