[PATCH] D42485: InstSimplify: If divisor element is undef simplify to undef
Zvi Rackover via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 24 09:23:58 PST 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL323343: InstSimplify: If divisor element is undef simplify to undef (authored by zvi, committed by ).
Repository:
rL LLVM
https://reviews.llvm.org/D42485
Files:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/test/Transforms/InstSimplify/div.ll
llvm/trunk/test/Transforms/InstSimplify/rem.ll
Index: llvm/trunk/test/Transforms/InstSimplify/rem.ll
===================================================================
--- llvm/trunk/test/Transforms/InstSimplify/rem.ll
+++ llvm/trunk/test/Transforms/InstSimplify/rem.ll
@@ -35,6 +35,22 @@
ret <2 x i8> %rem
}
+define <2 x i8> @srem_undef_elt_vec(<2 x i8> %x) {
+; CHECK-LABEL: @srem_undef_elt_vec(
+; CHECK-NEXT: ret <2 x i8> undef
+;
+ %rem = srem <2 x i8> %x, <i8 -42, i8 undef>
+ ret <2 x i8> %rem
+}
+
+define <2 x i8> @urem_undef_elt_vec(<2 x i8> %x) {
+; CHECK-LABEL: @urem_undef_elt_vec(
+; CHECK-NEXT: ret <2 x i8> undef
+;
+ %rem = urem <2 x i8> %x, <i8 undef, i8 42>
+ ret <2 x i8> %rem
+}
+
; Division-by-zero is undef. UB in any vector lane means the whole op is undef.
; Thus, we can simplify this: if any element of 'y' is 0, we can do anything.
; Therefore, assume that all elements of 'y' must be 1.
Index: llvm/trunk/test/Transforms/InstSimplify/div.ll
===================================================================
--- llvm/trunk/test/Transforms/InstSimplify/div.ll
+++ llvm/trunk/test/Transforms/InstSimplify/div.ll
@@ -34,6 +34,22 @@
ret <2 x i8> %div
}
+define <2 x i8> @sdiv_undef_elt_vec(<2 x i8> %x) {
+; CHECK-LABEL: @sdiv_undef_elt_vec(
+; CHECK-NEXT: ret <2 x i8> undef
+;
+ %div = sdiv <2 x i8> %x, <i8 -42, i8 undef>
+ ret <2 x i8> %div
+}
+
+define <2 x i8> @udiv_undef_elt_vec(<2 x i8> %x) {
+; CHECK-LABEL: @udiv_undef_elt_vec(
+; CHECK-NEXT: ret <2 x i8> undef
+;
+ %div = udiv <2 x i8> %x, <i8 undef, i8 42>
+ ret <2 x i8> %div
+}
+
; Division-by-zero is undef. UB in any vector lane means the whole op is undef.
; Thus, we can simplify this: if any element of 'y' is 0, we can do anything.
; Therefore, assume that all elements of 'y' must be 1.
Index: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp
@@ -868,13 +868,14 @@
if (match(Op1, m_Zero()))
return UndefValue::get(Ty);
- // If any element of a constant divisor vector is zero, the whole op is undef.
+ // If any element of a constant divisor vector is zero or undef, the whole op
+ // is undef.
auto *Op1C = dyn_cast<Constant>(Op1);
if (Op1C && Ty->isVectorTy()) {
unsigned NumElts = Ty->getVectorNumElements();
for (unsigned i = 0; i != NumElts; ++i) {
Constant *Elt = Op1C->getAggregateElement(i);
- if (Elt && Elt->isNullValue())
+ if (Elt && (Elt->isNullValue() || isa<UndefValue>(Elt)))
return UndefValue::get(Ty);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42485.131292.patch
Type: text/x-patch
Size: 2649 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180124/6047da58/attachment.bin>
More information about the llvm-commits
mailing list