[all-commits] [llvm/llvm-project] 62a0ec: Add support for !noundef metatdata on loads

Juneyoung Lee via All-commits all-commits at lists.llvm.org
Fri Oct 16 21:50:36 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 62a0ec1612bd6dee94f900f971afd409ddb62859
      https://github.com/llvm/llvm-project/commit/62a0ec1612bd6dee94f900f971afd409ddb62859
  Author: Juneyoung Lee <aqjune at gmail.com>
  Date:   2020-10-17 (Sat, 17 Oct 2020)

  Changed paths:
    M llvm/docs/LangRef.rst
    M llvm/include/llvm/IR/FixedMetadataKinds.def
    M llvm/lib/Analysis/ValueTracking.cpp
    M llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
    M llvm/test/Transforms/InstSimplify/freeze-noundef.ll

  Log Message:
  -----------
  Add support for !noundef metatdata on loads

This patch adds metadata !noundef and makes load instructions can optionally have it.
A load with !noundef always return a well-defined value (has no undef bit or isn't poison).
If the loaded value isn't well defined, the behavior is undefined.

This metadata can be used to encode the assumption from C/C++ that certain reads of variables should have well-defined values.
It is helpful for optimizing freeze instructions away, because freeze can be removed when its operand has well-defined value, and showing that a load from arbitrary location is well-defined is usually hard otherwise.

The same information can be encoded with llvm.assume with operand bundle; using metadata is chosen because I wasn't sure whether code motion can be freely done when llvm.assume is inserted from clang instead.
The existing codebase already is stripping unknown metadata when doing code motion, so using metadata is UB-safe as well.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D89050




More information about the All-commits mailing list