Open XChy opened 8 months ago
Hi!
This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:
test/
create fine-grained testing targets, so you can e.g. use make check-clang-ast
to only run Clang's AST tests.git clang-format HEAD~1
to format your changes.If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.
@llvm/issue-subscribers-good-first-issue
Author: XChy (XChy)
@dtcxzyw, I would like to take this one.
@dtcxzyw
I have been reviewing the code and found this line: if (IsAShr && Shr->hasOneUse())
in the function foldICmpShrConstant
. I believe this is where the issue occurs when a shift operation has only one use. However, I want clarification on whether simply removing this condition will be sufficient, or if other cases need to be considered.
@dtcxzyw I have been reviewing the code and found this line:
if (IsAShr && Shr->hasOneUse())
in the functionfoldICmpShrConstant
. I believe this is where the issue occurs when a shift operation has only one use. However, I want clarification on whether simply removing this condition will be sufficient, or if other cases need to be considered.
Please refer to the prior commit adding the one-use check: https://github.com/llvm/llvm-project/commit/a66051c68a43af39f9fd962f71d58ae0efcf860d. You should be careful not to break min/max idioms.
Feel free to file a PR. I cannot offer any suggestion until I see some performance data from my pre-commit CI.
I think it's ok to file a PR to simply remove that condition and see how it break other patterns in @dtcxzyw's CI.
Alive2 proof: https://alive2.llvm.org/ce/z/4JKW9d
Motivating example
can be folded to:
This enables more optimizations for the other user of
shr
as I observe in benchmark. Unsigned case is in alive2 proof.Real-world motivation
Signed case is derived from z3/src/sat/smt/pb_solver.cpp (after O3 pipeline). Unsigned case is derived from z3/src/tactic/core/collect_occs.cpp (after O3 pipeline). The example above is a reduced version. If you're interested in the original suboptimal IR and optimal IR, email me please.
Let me know if you can confirm that it's an optimization opportunity, thanks.