[PATCH] D149076: [IR] Make hasPoisonGeneratingMetadata return false if has !noundef
luxufan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 24 09:53:23 PDT 2023
StephenFan created this revision.
StephenFan added a reviewer: nikic.
Herald added a subscriber: hiraditya.
Herald added a project: All.
StephenFan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
`hasPoisonGeneratingMetadata` is used by ValueTracking function
`canCreateUndefOrPoison`, if both poison generating metadata and
!noundef exists, then this instruction can not create undef or poison
actually.
But I am not sure if it is correct since !noundef can be dropped. If we
first do the transform based on !noundef, then we drop it in other
transforms, does it still correct?
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D149076
Files:
llvm/lib/IR/Instruction.cpp
llvm/test/Transforms/InstCombine/select-and-or.ll
Index: llvm/test/Transforms/InstCombine/select-and-or.ll
===================================================================
--- llvm/test/Transforms/InstCombine/select-and-or.ll
+++ llvm/test/Transforms/InstCombine/select-and-or.ll
@@ -601,3 +601,20 @@
%r = select <2 x i1> %cond, <2 x i1> %a, <2 x i1> %b
ret <2 x i1> %r
}
+
+define i1 @poison_metadata(i32 noundef %a, i1 %b) {
+; CHECK-LABEL: @poison_metadata(
+; CHECK-NEXT: [[C:%.*]] = call i32 @llvm.ctpop.i32(i32 [[A:%.*]]), !range [[RNG0:![0-9]+]], !noundef !1
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C]], 3
+; CHECK-NEXT: [[R:%.*]] = and i1 [[CMP]], [[B:%.*]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %c = call i32 @llvm.ctpop.i32(i32 %a), !range !0, !noundef !1
+ %cmp = icmp ugt i32 %c, 2
+ %r = select i1 %b, i1 %cmp, i1 false
+ ret i1 %r
+}
+
+!0 = !{i32 0, i32 4}
+!1 = !{}
+declare i32 @llvm.ctpop.i32(i32)
Index: llvm/lib/IR/Instruction.cpp
===================================================================
--- llvm/lib/IR/Instruction.cpp
+++ llvm/lib/IR/Instruction.cpp
@@ -213,9 +213,10 @@
}
bool Instruction::hasPoisonGeneratingMetadata() const {
- return hasMetadata(LLVMContext::MD_range) ||
- hasMetadata(LLVMContext::MD_nonnull) ||
- hasMetadata(LLVMContext::MD_align);
+ return (hasMetadata(LLVMContext::MD_range) ||
+ hasMetadata(LLVMContext::MD_nonnull) ||
+ hasMetadata(LLVMContext::MD_align)) &&
+ !hasMetadata(LLVMContext::MD_noundef);
}
void Instruction::dropPoisonGeneratingMetadata() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149076.516446.patch
Type: text/x-patch
Size: 1540 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230424/60c7da0f/attachment.bin>
More information about the llvm-commits
mailing list