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