Skip to content

[OptimizeInstructions] Remove redundant sign-exts - #9324

Merged
tlively merged 14 commits into
mainfrom
opt-inst-1-3-redundant-sign-ext
Nov 9, 2026
Merged

tlively merged 14 commits into
mainfrom
opt-inst-1-3-redundant-sign-ext

Conversation

@tlively

@tlively tlively commented Oct 29, 2026

Copy link
Copy Markdown
Member

Relax isSignExted to check signExtBits <= bits, teach getSignExtBits about signed narrow loads and i64.extend_i32_s, remove unary sign-extensions when maxBits < bits, strip wider inner sign-extensions inside narrower outer ones, and fold i64.extend32_s(i64.extend_i32_u(x)) to i64.extend_i32_s(x).

Relax isSignExted to check signExtBits <= bits, teach getSignExtBits about signed narrow loads and i64.extend_i32_s, remove unary sign-extensions when maxBits < bits, strip wider inner sign-extensions inside narrower outer ones, and fold i64.extend32_s(i64.extend_i32_u(x)) to i64.extend_i32_s(x).
@tlively
tlively requested a review from a team as a code owner October 29, 2026 04:56
@tlively
tlively requested review from aheejin and removed request for a team October 29, 2026 04:56

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request enhances sign-extension optimizations in the OptimizeInstructions pass. It introduces a helper method getExpressionSignExtBits to track sign-extension widths, optimizes nested and redundant sign-extensions (both shift-based and unary), and simplifies expressions where the input's maximum bits are already within the target sign-extend limit. The feedback suggests a minor code cleanup to avoid a redundant cast by utilizing an already-bound pointer variable.

Comment thread src/passes/OptimizeInstructions.cpp Resolved

@aheejin aheejin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be easier to understand to have each if case comment in the code has a simple example attached to it.

Comment thread src/passes/OptimizeInstructions.cpp Resolved
Comment thread src/passes/OptimizeInstructions.cpp Resolved
Comment thread src/passes/OptimizeInstructions.cpp Resolved
Comment thread src/passes/OptimizeInstructions.cpp Resolved
Comment thread src/passes/OptimizeInstructions.cpp Resolved
Comment thread src/passes/OptimizeInstructions.cpp Resolved
Comment thread src/passes/OptimizeInstructions.cpp Resolved
Comment thread src/passes/OptimizeInstructions.cpp Resolved
Merge OptimizeInstructions::getSignExtBits into Properties::getSignExtBits using an optional LocalInfoProvider (following Bits::getMaxBits), and rename the sign/zero-extension bit width helpers from get*ExtBits to get*ExtKeptBits to clarify that they return the number of low bits kept before extension rather than the number of extended sign/zero bits.
# Conflicts:
#	src/passes/OptimizeInstructions.cpp
Merge OptimizeInstructions::getSignExtBits into Properties::getSignExtBits using an optional LocalInfoProvider (following Bits::getMaxBits), and rename the sign/zero-extension bit width helpers from get*ExtBits to get*ExtKeptBits to clarify that they return the number of low bits kept before extension rather than the number of extended sign/zero bits.
# Conflicts:
#	src/ir/properties.h
#	src/passes/OptimizeInstructions.cpp
…t-sign-ext

# Conflicts:
#	src/ir/bits.h
#	src/ir/properties.h
#	src/passes/OptimizeInstructions.cpp
#	src/passes/PickLoadSigns.cpp

@github-actions github-actions 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.

🤖 Google Antigravity Code Review

I have reviewed the changes in this Pull Request and left inline feedback.

Comment thread src/ir/bits.h Resolved
@tlively
tlively enabled auto-merge (squash) November 9, 2026 21:48
@tlively
tlively merged commit 20120df into main Nov 9, 2026
18 checks passed
@tlively
tlively deleted the opt-inst-1-3-redundant-sign-ext branch November 9, 2026 22:31
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.

2 participants