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: [email protected]
          Reporter: [email protected]
                CC: [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to