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

            Bug ID: 43420
           Summary: __builtin_constant_p resolves differently with loop
                    unrolling at -O3
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Interprocedural Optimizations
          Assignee: unassignedb...@nondot.org
          Reporter: ndesaulni...@google.com
                CC: isanb...@gmail.com, jykni...@google.com,
                    llvm-bugs@lists.llvm.org, srhi...@google.com
            Blocks: 4068

void c(void);

void a(void) {
  for (int b = 0x10; b; b <<= 1)
    if (__builtin_constant_p(b))
      __bad_udelay();
    else
      c();
}

Clang at -O2 and GCC at -O3 look similar.  At -O3, LLVM unrolls the loop 27
times, but b is no longer an ICE or rather BCP evaluates to false.  This
triggers a miscompile (__bad_udelay is purposely undefined) in the Linux kernel
at -O3.

https://godbolt.org/z/oDPVLO


Referenced Bugs:

https://bugs.llvm.org/show_bug.cgi?id=4068
[Bug 4068] [Meta] Compiling the Linux kernel with clang
-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to