Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Missing conditional optimization compared to gcc #15964

Open Quuxplusone opened 11 years ago

Quuxplusone commented 11 years ago
Bugzilla Link PR15964
Status NEW
Importance P normal
Reported by Jeff Muizelaar (jmuizelaar@mozilla.com)
Reported on 2013-05-10 13:17:22 -0700
Last modified on 2021-06-14 09:41:46 -0700
Version trunk
Hardware PC All
CC baldrick@free.fr, david.majnemer@gmail.com, hans@chromium.org, llvm-bugs@lists.llvm.org, rafael@espindo.la
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
The following two programs give the same result with gcc but B produces worse
code with clang.

A:
int
PL_strcasecmp(const char *a, const char *b)
{

    while( (*a == *b) && ('\0' != *a))
    {
        a++;
        b++;
    }

    return *a - *b;
}

B:
int
PL_strcasecmp(const char *a, const char *b)
{

    while( (*a == *b) && ('\0' != *a) && ('\0' != *b))
    {
        a++;
        b++;
    }

    return *a - *b;
}
Quuxplusone commented 11 years ago
Reduced:

; ModuleID = '/var/tmp/pr15964.ll'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-
f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nounwind readnone uwtable
define i1 @PL_strcasecmpA(i8 %a, i8 %b) #0 {
entry:
  %cmp = icmp eq i8 %a, %b
  %cmp4 = icmp ne i8 %a, 0
  %cmp4. = and i1 %cmp, %cmp4
  ret i1 %cmp4.
}

; Function Attrs: nounwind readnone uwtable
define i1 @PL_strcasecmpB(i8 %a, i8 %b) #0 {
entry:
  %cmp7 = icmp ne i8 %b, 0
  %notlhs = icmp eq i8 %a, %b
  %notrhs = icmp ne i8 %a, 0
  %not.or.cond = and i1 %notrhs, %notlhs
  %.cmp7 = and i1 %cmp7, %not.or.cond
  ret i1 %.cmp7
}

attributes #0 = { nounwind readnone uwtable }
Quuxplusone commented 3 years ago

It looks like GCC 9 started compiling these differently