Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tree-ssa-strlen] missing strlen optimization of the empty string #16

Open
xiangzhai opened this issue Jan 23, 2018 · 0 comments
Open
Labels
Milestone

Comments

@xiangzhai
Copy link

xiangzhai commented Jan 23, 2018

Hi fellows,

As PR83190 mentioned:
Testcase:

$ cat a.c
int f (void)
{
  char a[] = "012\0";

  return __builtin_strlen (a + 3);   // GCC 8.x folded into 0, but GCC 5.x failed
}

int g (void)
{
  char a[] = "012\0";

  return __builtin_strlen (a + 4);   // not folded
}

GCC 5.5 failed to fold for f and g:

;; Function f (f, funcdef_no=0, decl_uid=1486, cgraph_uid=0, symbol_order=0)

f ()
{
  char a[5];
  long unsigned int _3;
  int _4;

  <bb 2>:
  a = "012";
  _3 = __builtin_strlen (&MEM[(void *)&a + 3B]);
  _4 = (int) _3;
  a ={v} {CLOBBER};
  return _4;

}



;; Function g (g, funcdef_no=1, decl_uid=1490, cgraph_uid=1, symbol_order=1)

g ()
{
  char a[5];
  long unsigned int _3;
  int _4;

  <bb 2>:
  a = "012";
  _3 = __builtin_strlen (&MEM[(void *)&a + 4B]);
  _4 = (int) _3;
  a ={v} {CLOBBER};
  return _4;

}

And GCC 8.x only failed to fold for g:

;; Function f (f, funcdef_no=0, decl_uid=1582, cgraph_uid=0, symbol_order=0)

f ()
{
  <bb 2> [local count: 1073741825]:
  return 0;

}



;; Function g (g, funcdef_no=1, decl_uid=1586, cgraph_uid=1, symbol_order=1)

g ()
{
  char a[5];
  long unsigned int _1;
  int _4;

  <bb 2> [local count: 1073741825]:
  a = "012";
  _1 = __builtin_strlen (&MEM[(void *)&a + 4B]);
  _4 = (int) _1;
  a ={v} {CLOBBER};
  return _4;

}

But LLVM 7.x works:

$ /home/xiangzhai/llvm-build/bin/clang -O2 -S -emit-llvm a.c
$ cat a.ll
; ModuleID = 'a.c'
source_filename = "a.c"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-redhat-linux"

; Function Attrs: norecurse nounwind readnone uwtable
define i32 @f() local_unnamed_addr #0 {
  ret i32 0 ; <-- folded
}

; Function Attrs: norecurse nounwind readnone uwtable
define i32 @g() local_unnamed_addr #0 {
  ret i32 0 ; <-- folded
}

attributes #0 = { norecurse nounwind readnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }

!llvm.module.flags = !{!0}
!llvm.ident = !{!1}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"LLVM China clang version 7.0.0 (git@github.com:llvm-mirror/clang.git 87bcdaa7f2311f57c35c18efc6cbf5a973a67de7) (git@github.com:llvm-mirror/llvm.git 4eeea16aaacd6134fd411abcdbab15b630f3302b) (based on LLVM 7.0.0svn)"}

Regards,
Leslie Zhai

@xiangzhai xiangzhai added the bug label Jan 23, 2018
@xiangzhai xiangzhai added this to the gcc-8-branch milestone Feb 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant