[llvm-bugs] [Bug 51783] New: Missed arithmetic fold

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Sep 7 08:17:59 PDT 2021


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

            Bug ID: 51783
           Summary: Missed arithmetic fold
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: llvm at rifkin.dev
                CC: llvm-bugs at lists.llvm.org

LLVM optimizes bar into tgt here but not foo.

https://godbolt.org/z/jdeT7jbjd

int foo(int a, int b) {
    return b * (1 + a / b) - a;
}
int bar(int a, int b) {
    return b * (a / b) + b - a;
}
int tgt(int a, int b) {
    return b - a % b;
}

https://alive2.llvm.org/ce/z/axgBxW

GCC appears to miss this too.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210907/85cdc7e7/attachment.html>


More information about the llvm-bugs mailing list