aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/Local.cpp
diff options
context:
space:
mode:
authorRyan Buchner <92571492+bababuck@users.noreply.github.com>2025-04-02 09:56:09 -0700
committerGitHub <noreply@github.com>2025-04-02 09:56:09 -0700
commitfa2a6d68c6f35e478af3425760ae39e866049eee (patch)
tree7a0e11206e095b19e5a1212db459603788c80ff3 /llvm/lib/Transforms/Utils/Local.cpp
parent74ec038ffb34575ee93fa313cd0ea0db0c0a7e0a (diff)
downloadllvm-fa2a6d68c6f35e478af3425760ae39e866049eee.zip
llvm-fa2a6d68c6f35e478af3425760ae39e866049eee.tar.gz
llvm-fa2a6d68c6f35e478af3425760ae39e866049eee.tar.bz2
[CodeGenPrepare][RISCV] Combine (X ^ Y) and (X == Y) where appropriate (#130922)
Fixes #130510. In RISCV, modify the folding of (X ^ Y == 0) -> (X == Y) to account for cases where the (X ^ Y) will be re-used. If a constant is being used for the XOR before a branch, ensure that it is small enough to fit within a 12-bit immediate field. Otherwise, the equality check is more efficient than the check against 0, see the following: ``` # %bb.0: lui a1, 5 addiw a1, a1, 1365 xor a0, a0, a1 beqz a0, .LBB0_2 # %bb.1: ret .LBB0_2: ``` ``` # %bb.0: lui a1, 5 addiw a1, a1, 1365 beq a0, a1, .LBB0_2 # %bb.1: xor a0, a0, a1 ret .LBB0_2: ``` Similarly, if the XOR is between 1 and a size one integer, we should still fold away the XOR since that comparison can be optimized as a comparison against 0. ``` # %bb.0: slt a0, a0, a1 xor a0, a0, 1 beqz a0, .LBB0_2 # %bb.1: ret .LBB0_2: ``` ``` # %bb.0: slt a0, a0, a1 bnez a0, .LBB0_2 # %bb.1: xor a0, a0, 1 ret .LBB0_2: ``` One question about my code is that I used a hard-coded value for the width of a RISCV ALU immediate. Do you know of a way that I can gather this from the `context`, I was unable to devise one.
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
0 files changed, 0 insertions, 0 deletions