[llvm-dev] A question about the widely used "xxx | true" inside llvm

Shoaib Meenai via llvm-dev llvm-dev at lists.llvm.org
Sun Aug 19 22:15:49 PDT 2018


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".

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.
}

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."


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180820/4e3c2453/attachment.html>


More information about the llvm-dev mailing list