[cfe-dev] Evaluate constant condition of if statement has no effect
Frozen via cfe-dev
cfe-dev at lists.llvm.org
Sun Aug 20 21:28:32 PDT 2017
Simple Example:
int main()
{
int x;
if (x || 1) {}
}
Clang can not evaluate this condition and will emit IR like this:
define signext i32 @main() #0 {
entry:
%retval = alloca i32, align 4
%x = alloca i32, align 4
store i32 0, i32* %retval, align 4
%0 = load i32, i32* %x, align 4
%tobool = icmp ne i32 %0, 0
br i1 %tobool, label %if.then, label %lor.lhs.false
lor.lhs.false: ; preds = %entry
br i1 true, label %if.then, label %if.end
if.then: ; preds = %lor.lhs.false, %entry
br label %if.end
if.end: ; preds = %if.then, %lor.lhs.false
%1 = load i32, i32* %retval, align 4
ret i32 %1
}
However, when we swap the position of LHS and RHS(i.e. if (1 || x), Clang can recognize it:
define signext i32 @main() #0 {
entry:
%x = alloca i32, align 4
ret i32 0
}
I also find the root issue and propose one potential solution in comment 2 of this link: https://bugs.llvm.org/show_bug.cgi?id=34229
Any idea?
Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170821/ff47b196/attachment.html>
More information about the cfe-dev
mailing list