[llvm] 7fc0efd - [InstCombine] Add !noundef to match behavior of violating assume
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 21 08:18:15 PDT 2023
Author: luxufan
Date: 2023-06-21T23:17:57+08:00
New Revision: 7fc0efd0dc4d748ee1e1273f8afec289763c5049
URL: https://github.com/llvm/llvm-project/commit/7fc0efd0dc4d748ee1e1273f8afec289763c5049
DIFF: https://github.com/llvm/llvm-project/commit/7fc0efd0dc4d748ee1e1273f8afec289763c5049.diff
LOG: [InstCombine] Add !noundef to match behavior of violating assume
The behaviors of violating assume instruction or !nonnull metadata is
different. The former is immediate undefined behavior, but the latter is
returning poison value. This patch adds !noundef to trigger immediate
undefined behavior if !nonnull is violated.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D153400
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/test/Transforms/InstCombine/assume.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 0c695109654c4..c30c56a418ca5 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -2652,6 +2652,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
isValidAssumeForContext(II, LHS, &DT)) {
MDNode *MD = MDNode::get(II->getContext(), std::nullopt);
LHS->setMetadata(LLVMContext::MD_nonnull, MD);
+ LHS->setMetadata(LLVMContext::MD_noundef, MD);
return RemoveConditionFromAssume(II);
// TODO: apply nonnull return attributes to calls and invokes
diff --git a/llvm/test/Transforms/InstCombine/assume.ll b/llvm/test/Transforms/InstCombine/assume.ll
index bd909ad582e18..48095cf8b13b1 100644
--- a/llvm/test/Transforms/InstCombine/assume.ll
+++ b/llvm/test/Transforms/InstCombine/assume.ll
@@ -266,7 +266,7 @@ define i32 @bundle2(ptr %P) {
define i1 @nonnull1(ptr %a) {
; CHECK-LABEL: @nonnull1(
-; CHECK-NEXT: [[LOAD:%.*]] = load ptr, ptr [[A:%.*]], align 8, !nonnull !6
+; CHECK-NEXT: [[LOAD:%.*]] = load ptr, ptr [[A:%.*]], align 8, !nonnull !6, !noundef !6
; CHECK-NEXT: tail call void @escape(ptr nonnull [[LOAD]])
; CHECK-NEXT: ret i1 false
;
More information about the llvm-commits
mailing list