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

            Bug ID: 52190
           Summary: Missed optimization for ashr with zero or all ones as
                    LHS
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]

LLVM does optimize these cases - remove ashr:
int ok(__int128 f, int g)
{
    return (f >> 127) >> g;
}

int ok2(int f, int g)
{
    return (f >> 31) >> g;
}
int ok3(int f, int g)
{
    if (f == 0 || f == 1)
      return (-f) >> g;
    __builtin_unreachable();
}

But not these:
int bad1(int f, int g)
{
    if (f == 0 || f == -1)
      return f >> g;
    __builtin_unreachable();
}
int bad2(int f, int g)
{
    if (f == 0 || f == 1)
      return (f-1) >> g;
    return 0;
}

int bad3(int f, int g)
{
    if (f == 6 || f == 7)
      return (f-7) >> g;
    __builtin_unreachable();
}

https://godbolt.org/z/4P8vWcnWj

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