[llvm] 582901d - [ValueTracking] Let isGuaranteedNotToBeUndefOrPoison consider noundef
Juneyoung Lee via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 16 20:53:33 PDT 2020
Author: Juneyoung Lee
Date: 2020-07-17T12:53:08+09:00
New Revision: 582901d0b53a2a23ec91a6210e933a622b0bb739
URL: https://github.com/llvm/llvm-project/commit/582901d0b53a2a23ec91a6210e933a622b0bb739
DIFF: https://github.com/llvm/llvm-project/commit/582901d0b53a2a23ec91a6210e933a622b0bb739.diff
LOG: [ValueTracking] Let isGuaranteedNotToBeUndefOrPoison consider noundef
This patch adds support for noundef arguments.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D83752
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Transforms/InstSimplify/freeze-noundef.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index bc8f02972de8..8d7bb1805a57 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4766,6 +4766,12 @@ bool llvm::isGuaranteedNotToBeUndefOrPoison(const Value *V,
// TODO: Some instructions are guaranteed to return neither undef
// nor poison if their arguments are not poison/undef.
+ if (auto *A = dyn_cast<Argument>(V)) {
+ // NoUndef does not guarantee that paddings are not undef.
+ if (A->hasAttribute(Attribute::NoUndef))
+ return true;
+ }
+
if (auto *C = dyn_cast<Constant>(V)) {
// TODO: We can analyze ConstExpr by opcode to determine if there is any
// possibility of poison.
diff --git a/llvm/test/Transforms/InstSimplify/freeze-noundef.ll b/llvm/test/Transforms/InstSimplify/freeze-noundef.ll
index 466d4bb6ff66..424477891058 100644
--- a/llvm/test/Transforms/InstSimplify/freeze-noundef.ll
+++ b/llvm/test/Transforms/InstSimplify/freeze-noundef.ll
@@ -3,8 +3,7 @@
define i8 @noundef(i8 noundef %x) {
; CHECK-LABEL: @noundef(
-; CHECK-NEXT: [[Y:%.*]] = freeze i8 [[X:%.*]]
-; CHECK-NEXT: ret i8 [[Y]]
+; CHECK-NEXT: ret i8 [[X:%.*]]
;
%y = freeze i8 %x
ret i8 %y
@@ -13,14 +12,14 @@ define i8 @noundef(i8 noundef %x) {
define i1 @icmp(i8 noundef %x, i8 noundef %y) {
; CHECK-LABEL: @icmp(
; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT: [[F:%.*]] = freeze i1 [[C]]
-; CHECK-NEXT: ret i1 [[F]]
+; CHECK-NEXT: ret i1 [[C]]
;
%c = icmp eq i8 %x, %y
%f = freeze i1 %c
ret i1 %f
}
+; TODO: should look into binary operations
define i1 @or(i1 noundef %x, i1 noundef %x2) {
; CHECK-LABEL: @or(
; CHECK-NEXT: [[Y:%.*]] = or i1 [[X:%.*]], [[X2:%.*]]
@@ -43,6 +42,7 @@ define i1 @or2(i1 noundef %x, i1 %x2) {
ret i1 %z
}
+; TODO: should look into binary operations
define i8 @add(i8 noundef %x) {
; CHECK-LABEL: @add(
; CHECK-NEXT: [[Y:%.*]] = add i8 [[X:%.*]], 1
@@ -67,13 +67,13 @@ define i8 @addnsw(i8 noundef %x) {
define {i8, i32} @aggr({i8, i32} noundef %x) {
; CHECK-LABEL: @aggr(
-; CHECK-NEXT: [[Y:%.*]] = freeze { i8, i32 } [[X:%.*]]
-; CHECK-NEXT: ret { i8, i32 } [[Y]]
+; CHECK-NEXT: ret { i8, i32 } [[X:%.*]]
;
%y = freeze {i8, i32} %x
ret {i8, i32} %y
}
+; TODO: should look into extract operations
define i32 @extract({i8, i32} noundef %x) {
; CHECK-LABEL: @extract(
; CHECK-NEXT: [[Y:%.*]] = extractvalue { i8, i32 } [[X:%.*]], 1
@@ -85,6 +85,7 @@ define i32 @extract({i8, i32} noundef %x) {
ret i32 %z
}
+; TODO: should look into extract operations
define i32 @extract2({i8, {i8, i32}} noundef %x) {
; CHECK-LABEL: @extract2(
; CHECK-NEXT: [[Y:%.*]] = extractvalue { i8, { i8, i32 } } [[X:%.*]], 1
More information about the llvm-commits
mailing list