[PATCH] D29015: [SimpleLoopUnswitch] Fix introduction of UB when hoisted condition may be undef or poison

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 27 18:02:19 PDT 2020


aqjune added a comment.

Now we have a pass for removing freezes in a loop (D77524 <https://reviews.llvm.org/D77524>). I can check whether the existing slowdowns can be addressed with it. I'll be a bit busy for a month, so it may proceed a bit slowly.
BTW, having an attribute for function arguments that states the value is already frozen will be really helpful for reducing the amount of introduced freezes (not only for loop unswitch, but also for other transformations that need freeze operations). I remember that it was called `nonpoison` in the previous llvm-dev discussion.
According to C/C++ standard, if indeterminate value is produced by an evaluation, the behavior is undefined except when the value was a family of char type:
C++14: https://timsong-cpp.github.io/cppwp/n4140/dcl.init#12
C++17: https://timsong-cpp.github.io/cppwp/n4659/dcl.init#12
C++11: https://timsong-cpp.github.io/cppwp/n3337/conv.lval#1 (wording is a bit different)
C11: https://port70.net/~nsz/c/c11/n1570.html#6.3.2.1p2
This means that it is valid to put the attribute unless the type is char or an aggregate with char when translating C/C++ to IR.
What do you think? @jdoerfert @reames This will help support other optimizations, such as supporting hoisting divisions from a loop when its divisor is a non-zero value derived from a function argument.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D29015





More information about the llvm-commits mailing list