[PATCH] D75815: [InstCombine] Simplify calls with "returned" attribute

Alexander Potapenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 26 03:45:26 PDT 2020


glider added a comment.

In D75815#1941004 <https://reviews.llvm.org/D75815#1941004>, @lebedev.ri wrote:

> I'm going to guess `__attribute__((no_sanitize()))` needs to also imply (read: implicitly add) `noinline` attribute,
>  but even that is not sufficient to block inter-procedural optimizations.
>  See also disscussion in https://reviews.llvm.org/D53431


I don't think `noinline` works here:

  __attribute__((__noinline__))
  int KMSAN_INIT_INT(int value)
  {
   return value;
  }
  
  int bar(int value) {
    value = KMSAN_INIT_INT(value);
    if (value < 0)
      value *= -1; 
    return value;
  }

(see also https://godbolt.org/z/r5fKT2)

The resulting IR shows that KMSAN_INIT_INT has the noinline attribute, but it effectively ends up being inlined in this case:

  ; Function Attrs: noinline norecurse nounwind readnone uwtable
  define dso_local i32 @KMSAN_INIT_INT(i32 returned %value) local_unnamed_addr #0 {
  entry:
    ret i32 %value
  }
  
  ; Function Attrs: norecurse nounwind readnone uwtable
  define dso_local i32 @bar(i32 %value) local_unnamed_addr #1 {
  entry:
    %cmp = icmp slt i32 %value, 0
    %mul = sub nsw i32 0, %value
    %spec.select = select i1 %cmp, i32 %mul, i32 %value
    ret i32 %spec.select
  }



> All these semantic guarantees for sanitize_memory functions are rather underspecified in langref.
>  I'm not sure it is good idea to try to enforce them without codifying them first.

You're right, we'll have to write them down. But in the case of noinline attribute langref is pretty clear on this subject: "This attribute indicates that the inliner should never inline this function in any situation."


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75815/new/

https://reviews.llvm.org/D75815





More information about the llvm-commits mailing list