https://bugs.llvm.org/show_bug.cgi?id=43497

            Bug ID: 43497
           Summary: Missed optimization: Conditional multiply by -1.0 or
                    1.0 not simplified to negation
           Product: libraries
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]

Conditionally multiplying a f64 by -1.0 or 1.0 does not get optimized into a
conditional negation.

Code to reproduce:

pub fn a(num: f64, is_neg: bool) -> f64 {
    num * if is_neg {
        -1.0
    } else {
        1.0
    }
}

pub fn b(num: f64, is_neg: bool) -> f64 {
    if is_neg {
        -num
    } else {
        num
    }
}

https://rust.godbolt.org/z/wp28oz

Function a does not get optimized as the same as function b. The equivalent C++
code is properly optimized in GCC.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to