[PATCH] D149699: [InstCombine] Improve bswap optimization

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 7 22:55:15 PDT 2023


goldstein.w.n added a comment.

In D149699#4325654 <https://reviews.llvm.org/D149699#4325654>, @austin880625 wrote:

> I'm not able to reproduce the failure with the given IR. Does the failure persist if the `and` in the `bswap` are moved out as a separate instruction?
> Anyway maybe we should use `dyn_cast` with `if` check

I'm going to revert this for now so you can post the fix.
You can re-open this commit when you are ready.

The following:

  -  if (match(V, m_OneUse(m_BitwiseLogic(m_Value(X), m_Value(Y))))) {
  +  // Find bitwise logic op. Check that it is a BinaryOperator explicitly so we
  +  // don't match ConstantExpr that aren't meaningful for this transform.
  +  if (match(V, m_OneUse(m_BitwiseLogic(m_Value(X), m_Value(Y)))) &&
  +      isa<BinaryOperator>(V)) {

works for me and leaves both:

  @gp = external global [0 x i8]
  +
  +define void @foo(ptr %out, i64 %a) {
  +  %gpi = ptrtoint ptr @gp to i64
  +  %exp = and i64 %gpi, 4095
  +  %res = call i64 @llvm.bswap.i64(i64 %exp)
  +  store i64 %res, ptr %out, align 8
  +  ret void
  +}
  +
  +
  +define void @bar(ptr %out, i64 %a) {
  +  %gpi = ptrtoint ptr @gp to i64
  +  %bs_gpi = call i64 @llvm.bswap.i64(i64 %gpi)
  +  %exp = and i64 %bs_gpi, 4095
  +  %res = call i64 @llvm.bswap.i64(i64 %exp)
  +  store i64 %res, ptr %out, align 8
  +  ret void
  +}
  +

working ideally.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149699



More information about the llvm-commits mailing list