GithubHelp home page GithubHelp logo

Comments (3)

mysterymath avatar mysterymath commented on July 25, 2024

Yep, fair criticism. I ran this through godbolt, looks like it's coming down from the frontend as a 1-bit XOR:

# Machine code for function invert: IsSSA, TracksLiveness

bb.1.entry:
  liveins: $a
  %1:_(s8) = COPY $a
  %2:_(s8) = G_ASSERT_ZEXT %1:_, 1
  %0:_(s1) = G_TRUNC %2:_(s8)
  %3:_(s1) = G_CONSTANT i1 true
  %4:_(s1) = G_XOR %0:_, %3:_; example.c:3:12
  %5:_(s8) = G_ZEXT %4:_(s1); example.c:3:5
  $a = COPY %5:_(s8); example.c:3:5
  RTS implicit $a; example.c:3:5

# End machine code for function invert.

Our legalizer is lowering it to the following select:

# Machine code for function invert: IsSSA, TracksLiveness, Legalized

bb.1.entry:
  liveins: $a
  %1:_(s8) = COPY $a
  %2:_(s8) = G_ASSERT_ZEXT %1:_, 1
  %0:_(s1) = G_TRUNC %2:_(s8)
  %3:_(s1) = G_CONSTANT i1 true
  %6:_(s1) = G_CONSTANT i1 false
  %4:_(s1) = G_SELECT %0:_(s1), %6:_, %3:_; example.c:3:12
  %7:_(s8) = G_CONSTANT i8 1
  %8:_(s8) = G_CONSTANT i8 0
  %5:_(s8) = G_SELECT %4:_(s1), %7:_, %8:_; example.c:3:5
  $a = COPY %5:_(s8); example.c:3:5
  RTS implicit $a; example.c:3:5

# End machine code for function invert.

This is because 1-bit XORs are just how the IR happens to represent negation of boolean flag values, and it's usually better to lower those to control flow (which usually folds away to nothing) than to widen to 8 bits, XOR, then truncate.

But, in this case, the 1-bit XOR is immediately zero-extended (ZEXT) to 8 bits, so we might as well just compute an 8-bit XOR. Should be a relatively simple thing to fix.

from llvm-mos.

mysterymath avatar mysterymath commented on July 25, 2024

Fixed by 2b1d155

from llvm-mos.

mysterymath avatar mysterymath commented on July 25, 2024

Had to revert the fix to this, as it causes a pretty severe regression elsewhere.

This will take some doing; the game here is surprisingly tricky, and I don't fully understand all the behavior of all the pieces yet.

from llvm-mos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.