Giter VIP home page Giter VIP logo

Comments (4)

scottmcm avatar scottmcm commented on August 22, 2024 1

I think that if you want this you should write

 fn test<const SIZE: usize>() {
-  if SIZE < 4096 {
+  if const { SIZE < 4096 } {

so that rust will know it's a constant, and be more likely to give you the behaviour you want in unoptimized builds.

(Or make your own trait so it can be <[u8; 4096]>::IS_SMALL or something if you need an older MSRV.)

Anything else will just mean exactly the same bug comes back if you write it as SIZE.ilog2() < 12 instead, but if you write const { SIZE.ilog2() < 12 } that'd be fine again.

from rust.

CJacob314 avatar CJacob314 commented on August 22, 2024

@saethlin informed me that this is an issue with his mono-reachable traversal implementation.

from rust.

saethlin avatar saethlin commented on August 22, 2024

I know that when I initially worked on this I searched the generated LLVM IR for the special "No predecessors!" comment that LLVM leaves on such orphaned basic blocks. There are a lot and I think I concluded they were all not actionable.

Clearly this case is.

There are actually two bugs here:

  1. The mono-reachable traverasal only looks for a constant SwitchInt param coming from Rvalue::Use and Rvalue::UbChecks. In this case, we have Rvalue::BinOp. GVN could fix this, but only if test were inlined or we had post-mono MIR optimizations. So I lean towards it being worthwhile to teach mono-reachable traversal about this.

  2. Even if we get the traversal right (this can be simulated by wrapping the comparison in an inline const) we still have an alloca for the argument, because we don't set up locals based on reachability.

from rust.

CJacob314 avatar CJacob314 commented on August 22, 2024

@scottmcm That doesn't work, either. See version 1.80.0 or version 1.82.0-nightly on Compiler Explorer.

from rust.

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.