[PATCH] D99853: [InstSimplify] Teach isUndefValue to understand const vector with both undef & poison
Juneyoung Lee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 3 21:57:25 PDT 2021
aqjune created this revision.
aqjune added reviewers: spatel, lebedev.ri, nikic, fhahn.
aqjune requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
A constant vector that has both undef & poison, e.g., `<i8 undef, i8 poison>`, isn't `UndefValue`.
This causes `SimplifyQuery::isUndefValue` to return false even if it is.
This patch teaches the function to recognize such form as well.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D99853
Files:
llvm/include/llvm/Analysis/InstructionSimplify.h
llvm/test/Transforms/InstSimplify/icmp-constant.ll
Index: llvm/test/Transforms/InstSimplify/icmp-constant.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/icmp-constant.ll
+++ llvm/test/Transforms/InstSimplify/icmp-constant.ll
@@ -1069,8 +1069,7 @@
define <2 x i1> @heterogeneous_constvector(<2 x i8> %x) {
; CHECK-LABEL: @heterogeneous_constvector(
-; CHECK-NEXT: [[C:%.*]] = icmp ult <2 x i8> [[X:%.*]], <i8 undef, i8 poison>
-; CHECK-NEXT: ret <2 x i1> [[C]]
+; CHECK-NEXT: ret <2 x i1> zeroinitializer
;
%c = icmp ult <2 x i8> %x, <i8 undef, i8 poison>
ret <2 x i1> %c
Index: llvm/include/llvm/Analysis/InstructionSimplify.h
===================================================================
--- llvm/include/llvm/Analysis/InstructionSimplify.h
+++ llvm/include/llvm/Analysis/InstructionSimplify.h
@@ -133,7 +133,22 @@
bool isUndefValue(Value *V) const {
if (!CanUseUndef)
return false;
- return isa<UndefValue>(V);
+
+ if (isa<UndefValue>(V))
+ return true;
+
+ // Check whether V is e.g., <undef, poison>
+ Constant *C = dyn_cast<Constant>(V);
+ auto *FVTy = dyn_cast<FixedVectorType>(V->getType());
+ if (C && FVTy) {
+ for (unsigned i = 0, e = FVTy->getNumElements(); i != e; ++i) {
+ auto *EV = C->getAggregateElement(i);
+ if (!EV || !isa<UndefValue>(EV))
+ return false;
+ }
+ return true;
+ }
+ return false;
}
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99853.335128.patch
Type: text/x-patch
Size: 1444 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210404/23c1fa4a/attachment.bin>
More information about the llvm-commits
mailing list