]> git.lizzy.rs Git - rust.git/commit - src/librustc_llvm/build.rs
Rollup merge of #74491 - xldenis:constant-binop-opt, r=oli-obk
authorManish Goregaokar <manishsmail@gmail.com>
Fri, 24 Jul 2020 17:01:32 +0000 (10:01 -0700)
committerGitHub <noreply@github.com>
Fri, 24 Jul 2020 17:01:32 +0000 (10:01 -0700)
commite59effed3037701aadab11d4ea0ddddf2eedbf3b
tree806abbeb804a9e25d08bf88e06182518bb532134
parent3226d723381a24118f6aaa73b096c8ef4510f189
parent711a6807a7979715d6b2940db56eaf1585d30a71
Rollup merge of #74491 - xldenis:constant-binop-opt, r=oli-obk

Optimize away BitAnd and BitOr when possible

This PR lets `const_prop` optimize away `a | true == true` , `a & false == false` and `a * 0 = 0`. While I was writing this I've realized that constant propagation misses a lot of opportunities. For example:  https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=2a4b45e772f214210a36749b27223bb0

Constant propagation doesn't seem to... propagate constants, additionally the way constant propagation is currently setup makes it tricky to add cases like `a | false == a`.

I tried to organize `eval_rvalue_with_identities` to make the pattern of the optimizations easier to see but it still obscurs what should be a simple peephole optmization.

cc @oli-obk
src/librustc_mir/transform/const_prop.rs