[llvm-bugs] [Bug 48683] New: Missing known bits info for x*x

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jan 7 04:09:24 PST 2021


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

            Bug ID: 48683
           Summary: Missing known bits info for x*x
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at lists.llvm.org

bool foo(unsigned x) {
    return (x * x) & 2;
}


Square is always congruent to 0 or 1 mod 4 so we can fold it to return false
(For knownbits, second LSB is not set).

define i1 @src(i32 %0) {
%1:
  %2 = mul i32 %0, %0
  %3 = and i32 %2, 2
  %4 = icmp ne i32 %3, 0
  ret i1 %4
}
=>
define i1 @tgt(i32 %0) {
%1:
  ret i1 0
}
Transformation seems to be correct!

https://en.wikipedia.org/wiki/Quadratic_reciprocity

-- 
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/20210107/788464da/attachment-0001.html>


More information about the llvm-bugs mailing list