[llvm-dev] A question about the widely used "xxx | true" inside llvm
Justin Bogner via llvm-dev
llvm-dev at lists.llvm.org
Sun Aug 19 23:37:58 PDT 2018
Shoaib Meenai via llvm-dev <llvm-dev at lists.llvm.org> writes:
> This is better suited to llvm-dev, so I'm directing it there.
>
> From: llvm-commits <llvm-commits-bounces at lists.llvm.org> on behalf of
> Qing Shan Zhang via llvm-commits <llvm-commits at lists.llvm.org>
> Reply-To: Qing Shan Zhang <qshanz at cn.ibm.com>
> Date: Sunday, August 19, 2018 at 10:10 PM
> To: "llvm-commits at lists.llvm.org" <llvm-commits at lists.llvm.org>
> Subject: A question about the widely used "xxx | true" inside llvm
>
> Hi, guys,
>
> I notice that, we are widely using the statement "xxx | true" in llvm,
> such as "return SimplifyCFG(BB) | true;". I have no idea if there is
> any downside to use the logic operator "||" here. Instead, I indeed
> see the potential problem to use bitwise operator "|". Because the
> bitwise operator do not short-circuit and the language std didn't
> specify the evaluation order for its lhs and rhs expression. That
> means, compiler is free to optimize this statement to "return true".
I think "widely using" is overstating the issue. This seems to be
happening in a lot of places in SimplifyCFG though, and from looking at
the code and the history it's pretty clear to me that the uses of the
bitwise or are either stylistic or unintentional. I've gone ahead and
changed all of those to use || for clarity in r340153.
> In shorts, IMO, it is legal to do the following optimization:
> bool bar() {
> return foo() | true;
> }
> -->
> bool bar() {
> return true; // the call to foo() is missing.
> }
This is only legal if the compiler can prove that foo() has no side
effects, which isn't true in this case. Using bitwise or here is
certainly confusing, but there isn't a correctness issue.
> Best regards
>
> steven.zhang(张青山)
> XLC++ Compiler Frontend Developer
>
> IBM China Development Lab, Shanghai
> Tel: (8621)609-28454 Mobile: +8615900986116
> E-mail: qshanz at cn.ibm.com<mailto:qshanz at cn.ibm.com>
> 关注IBM中国编译器开发团队 - 新浪微博:
> http://www.weibo.com/ibmcompiler<https://urldefense.proofpoint.com/v2/url?u=http-3A__www.weibo.com_ibmcompiler&d=DwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Pq-hk0wEUZUsW1TCR5WSeKCTC9p-kFZHFQXEwhAc7-k&s=A_Y7Fzz24WHgMcnZjkQNCxix8GiaTORg0B7J-WtGp9c&e=>
> | developerWorks:
> http://t.cn/SPHWF4<https://urldefense.proofpoint.com/v2/url?u=http-3A__t.cn_SPHWF4&d=DwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Pq-hk0wEUZUsW1TCR5WSeKCTC9p-kFZHFQXEwhAc7-k&s=EJ9ZnKu_kAhWtR9SgL-C_ooRh7TCL-EGc0wAotg4wb4&e=>
>
> "All things are difficult before they are easy."
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
More information about the llvm-dev
mailing list