[PATCH] D139314: ValueTracking: Teach canCreateUndefOrPoison about FP ops

Aaron Ballman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 5 09:13:12 PST 2022


aaron.ballman added inline comments.


================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:5239
+      case Intrinsic::llrint:
+        // If the value doesn't fit an unspecified value is returned.
+        break;
----------------
aqjune wrote:
> Actually this part is slightly tricky, I think.
> In C++ an unspecified value is a well-defined value meaning that its usage does not introduce UB unless the operation is supposed to do so.
> This is different from undefined value or poison value because their usage may introduce UB.
> Therefore, I think we can say that `canCreateUndefOrPoison` can return `false` for these ops.
> I would like to cross-check my understanding with clang - @aaron.ballman May I ask whether my understanding is correct please?
> I would like to cross-check my understanding with clang - @aaron.ballman May I ask whether my understanding is correct please?

You're correct.

C2x 7.12.9.5p2: The lrint and llrint functions round their argument to the nearest integer value, rounding according to the current rounding direction. If the rounded value is outside the range of the return type, the numeric result is unspecified and a domain error or range error may occur.

C2x 3.19.3p1: unspecified value -- valid value of the relevant type where this document imposes no requirements on which value is chosen in any instance.

C2x 3.4.4p1: unspecified behavior -- behavior, that results from the use of an unspecified value, or other behavior upon which this
document provides two or more possibilities and imposes no further requirements on which is chosen in any instance.

The only assumption the optimizer is allowed to make about an unspecified value is that the object holds an arbitrary value that may change on any given access.


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

https://reviews.llvm.org/D139314



More information about the llvm-commits mailing list