[PATCH] D158673: [SDAG][RISCV] Avoid neg instructions when lowering atomic_load_sub with a constant rhs

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 23 14:31:33 PDT 2023


craig.topper added a comment.

Does this patch improve this too

  define signext i32 @atomicrmw_sub_i32_monotonic(ptr %a, i32 %x, i32 %y) nounwind {
  
    %b = sub i32 %x, %y
    %1 = atomicrmw sub ptr %a, i32 %b monotonic
    ret i32 %1
    }

it currently generates

  atomicrmw_sub_i32_monotonic:            # @atomicrmw_sub_i32_monotonic
          subw    a1, a1, a2
          neg     a1, a1
          amoadd.w        a0, a1, (a0)
          ret

But I think we could swap the operands to the subw to remove the neg.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158673/new/

https://reviews.llvm.org/D158673



More information about the llvm-commits mailing list