<div dir="ltr">HI,<div>By splitting the assert I am getting the following IR:</div><div><b><font face="monospace">define dso_local i32 @main() #0 {<br>entry:<br>  %c = alloca double, align 8<br>  %0 = call double @llvm.ceil.f64(double 0xFFF0000000000000)<br>  store double %0, double* %c, align 8<br>  %call = call i32 @__isinff(float 0x7FF0000000000000) #4<br>  %call1 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %call)<br>  %1 = load double, double* %c, align 8<br>  %2 = bitcast double %1 to i64<br>  %3 = icmp slt i64 %2, 0<br>  %4 = zext i1 %3 to i32<br>  %call2 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %4)<br>  ret i32 0<br>}</font></b><br></div><div>It's not the most optimal but still doesn't have as much unnecessary code. My main concern is why are signle, double and extended precision floats being checked for 'isinf', when the original code only asks for double, and this behaviour seems to be induced by the logical and operator.</div><div><br></div><div>Thanks,</div><div>Akash.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jan 30, 2020 at 2:17 PM Craig Topper <<a href="mailto:craig.topper@gmail.com">craig.topper@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">That code looks like it was compiled without any optimizations enabled. The IR without optimizations is meant to be easy for the frontend to generate. Even with the code split into two asserts, without optimizations enabled I see a lot of the same things unnecessary things.<div><br><div><div><div><div dir="ltr">~Craig</div></div><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jan 30, 2020 at 12:25 AM Akash Banerjee via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Please consider the following C code:<div><font face="monospace"><b>#include <math.h><br>int main(void) {<br>  double c = ceil(-INFINITY);<br>  assert(isinf(INFINITY) && signbit(c));<br>}</b></font><br></div><div><font face="monospace"><b><br></b></font></div><div>The following LLVM IR is generated for the above code by clang:</div><b><font face="monospace">define dso_local i32 @main() #0 {<br>entry:<br>  %retval = alloca i32, align 4<br>  %c = alloca double, align 8<br>  store i32 0, i32* %retval, align 4<br>  %0 = call double @llvm.ceil.f64(double 0xFFF0000000000000)<br>  store double %0, double* %c, align 8<br>  br i1 true, label %cond.true, label %cond.false    <font color="#ff0000">//Unnecessary conditional branch</font><br><br>cond.true:                                        ; preds = %entry<br>  %call = call i32 @__isinff(float 0x7FF0000000000000) #4<br>  %tobool = icmp ne i32 %call, 0<br>  br i1 %tobool, label %land.rhs, label %land.end<br><br>cond.false:                                       ; preds = %entry</font></b><font face="monospace"><b>    <font color="#ff0000">//Unnecessary Block</font></b></font><b><font face="monospace"><br>  br i1 false, label %cond.true1, label %cond.false4<br><br>cond.true1:                                       ; preds = %cond.false</font></b> <b><font face="monospace">   <font color="#ff0000">//Unnecessary Block</font><br>  %call2 = call i32 @__isinf(double 0x7FF0000000000000) #4<br>  %tobool3 = icmp ne i32 %call2, 0<br>  br i1 %tobool3, label %land.rhs, label %land.end<br><br>cond.false4:                                      ; preds = %cond.false   <font color="#ff0000">//Unnecessary Block</font><br>  %call5 = call i32 @__isinfl(x86_fp80 0xK7FFF8000000000000000) #4<br>  %tobool6 = icmp ne i32 %call5, 0<br>  br i1 %tobool6, label %land.rhs, label %land.end<br><br>land.rhs:                                         ; preds = %cond.false4, %cond.true1, %cond.true<br>  %1 = load double, double* %c, align 8<br>  %2 = bitcast double %1 to i64<br>  %3 = icmp slt i64 %2, 0<br>  br label %land.end<br><br>land.end:                                         ; preds = %land.rhs, %cond.false4, %cond.true1, %cond.true<br>  %4 = phi i1 [ false, %cond.false4 ], [ false, %cond.true1 ], [ false, %cond.true ], [ %3, %land.rhs ]<br>  %land.ext = zext i1 %4 to i32<br>  %call7 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %land.ext)<br>  %5 = load i32, i32* %retval, align 4<br>  ret i32 %5<br>}</font></b><div><br>This seems to happen because of the logical and operator in the assert, and instead, if the assert is split into two separate asserts:</div><div><font face="monospace"><b>    assert(isinf(INFINITY));</b></font></div><div><font face="monospace"><b>    assert(signbit(c));</b></font></div><div><font face="arial, sans-serif">, then the IR generated is fine.</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">Thanks,</font></div><div><font face="arial, sans-serif">Akash.</font></div></div>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div>
</blockquote></div>