Giter Site home page Giter Site logo

Comments (3)

nunoplopes avatar nunoplopes commented on June 11, 2024 1

Thank you @nunoplopes for your response! What puzzles me is that @llvm.uadd.with.overflow will be converted to the add + ult during legalization phase (LLVM common code is responsible for this), so does that mean we can get the same problem with undef like here?

No one said that LLVM was correct 🙂
Legalization at the end of the pipeline, so in practice it may not matter since assembly doesn't have undef. SDAG does have undef & poison, so I'm not saying everything is great, but the chances of miscompilations is low.
That's not true if done in the middle of the optimization pipeline. But these days. clang adds noundef to most (all?) function arguments, so it's relatively easy to ensure something isn't undef. You can also use freeze.

from alive2.

nunoplopes avatar nunoplopes commented on June 11, 2024

I'm sorry to say but the optimization is indeed incorrect when %arg1 is undef. You can see that Alive2 proves it correct if you add noundef to the first argument.
This is because @llvm.uadd.with.overflow does the addition and overflow check with the same value, while if you lower it into add+icmp, each operation may observe different values for %arg1m (undef can yield a different value each time it is used).

Take the counterexample, where %modulo = #x3.
Then %arg1m and %arg2m must be in [0,2] and so their sum never overflows. So %obit in src is always false.
On the other hand, in tgt, icmp ult %sum, %arg1m can yield true or false depending on the inputs. Then branching on a non-deterministic value is UB.

I know the counterexample isn't too easy to read. But the optimization is incorrect.

from alive2.

vladimirradosavljevic avatar vladimirradosavljevic commented on June 11, 2024

Thank you @nunoplopes for your response!
What puzzles me is that @llvm.uadd.with.overflow will be converted to the add + ult during legalization phase (LLVM common code is responsible for this), so does that mean we can get the same problem with undef like here?

from alive2.

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.