[PATCH] D33774: [CodeGen] Make __attribute__(const) calls speculatable

Eli Friedman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 1 10:30:41 PDT 2017


efriedma added a comment.

Consider something like this:

  define i32 @div(i32 %x, i32 %y) {
  entry:
    %div = sdiv i32 %x, %y
    ret i32 %div
  }

We can mark this function readnone, but not speculatable: it doesn't read or write memory, but could exhibit undefined behavior.

Consider another function:

  @x = common local_unnamed_addr global i32 0, align 4
  define i32 @get_x() {
  entry:
    %0 = load i32, i32* @x, align 4, !tbaa !2
    ret i32 %0
  }

We can mark this function speculatable, but not readnone: it doesn't exhibit undefined behavior or have side-effects, but it does read memory.

Given that, it seems a little dubious to translate `__attribute__((const))` into `speculatable`.


https://reviews.llvm.org/D33774





More information about the cfe-commits mailing list