llvm.org GIT mirror llvm / cc39aee
Merging r348462: ------------------------------------------------------------------------ r348462 | lebedevri | 2018-12-06 00:14:24 -0800 (Thu, 06 Dec 2018) | 13 lines [InstCombine] foldICmpWithLowBitMaskedVal(): don't miscompile -1 vector elts I was finally able to quantify what i thought was missing in the fix, it was vector constants. If we have a scalar (and %x, -1), it will be instsimplified before we reach this code, but if it is a vector, we may still have a -1 element. Thus, we want to avoid the fold if *at least one* element is -1. Or in other words, ignoring the undef elements, no sign bits should be set. Thus, m_NonNegative(). A follow-up for rL348181 https://bugs.llvm.org/show_bug.cgi?id=39861 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_70@348538 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 1 year, 10 months ago
3 changed file(s) with 16 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
29252925 return nullptr; // Ignore the other case.
29262926 if (!match(M, m_Constant())) // Can not do this fold with non-constant.
29272927 return nullptr;
2928 if (!match(M, m_NonNegative())) // Must not have any -1 vector elements.
2929 return nullptr;
29282930 DstPred = ICmpInst::Predicate::ICMP_SLE;
29292931 break;
29302932 case ICmpInst::Predicate::ICMP_SLT:
29322934 if (X != I.getOperand(1)) // X must be on RHS of comparison!
29332935 return nullptr; // Ignore the other case.
29342936 if (!match(M, m_Constant())) // Can not do this fold with non-constant.
2937 return nullptr;
2938 if (!match(M, m_NonNegative())) // Must not have any -1 vector elements.
29352939 return nullptr;
29362940 DstPred = ICmpInst::Predicate::ICMP_SGT;
29372941 break;
204204
205205 define <2 x i1> @n3_vec(<2 x i8> %x) {
206206 ; CHECK-LABEL: @n3_vec(
207 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt <2 x i8> [[X:%.*]],
208 ; CHECK-NEXT: ret <2 x i1> [[TMP1]]
207 ; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X:%.*]],
208 ; CHECK-NEXT: [[RET:%.*]] = icmp sge <2 x i8> [[TMP0]], [[X]]
209 ; CHECK-NEXT: ret <2 x i1> [[RET]]
209210 ;
210211 %tmp0 = and <2 x i8> %x,
211212 %ret = icmp sge <2 x i8> %tmp0, %x
214215
215216 define <3 x i1> @n4_vec(<3 x i8> %x) {
216217 ; CHECK-LABEL: @n4_vec(
217 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt <3 x i8> [[X:%.*]],
218 ; CHECK-NEXT: ret <3 x i1> [[TMP1]]
218 ; CHECK-NEXT: [[TMP0:%.*]] = and <3 x i8> [[X:%.*]],
219 ; CHECK-NEXT: [[RET:%.*]] = icmp sge <3 x i8> [[TMP0]], [[X]]
220 ; CHECK-NEXT: ret <3 x i1> [[RET]]
219221 ;
220222 %tmp0 = and <3 x i8> %x,
221223 %ret = icmp sge <3 x i8> %tmp0, %x
204204
205205 define <2 x i1> @n3(<2 x i8> %x) {
206206 ; CHECK-LABEL: @n3(
207 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <2 x i8> [[X:%.*]],
208 ; CHECK-NEXT: ret <2 x i1> [[TMP1]]
207 ; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X:%.*]],
208 ; CHECK-NEXT: [[RET:%.*]] = icmp slt <2 x i8> [[TMP0]], [[X]]
209 ; CHECK-NEXT: ret <2 x i1> [[RET]]
209210 ;
210211 %tmp0 = and <2 x i8> %x,
211212 %ret = icmp slt <2 x i8> %tmp0, %x
214215
215216 define <3 x i1> @n4(<3 x i8> %x) {
216217 ; CHECK-LABEL: @n4(
217 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <3 x i8> [[X:%.*]],
218 ; CHECK-NEXT: ret <3 x i1> [[TMP1]]
218 ; CHECK-NEXT: [[TMP0:%.*]] = and <3 x i8> [[X:%.*]],
219 ; CHECK-NEXT: [[RET:%.*]] = icmp slt <3 x i8> [[TMP0]], [[X]]
220 ; CHECK-NEXT: ret <3 x i1> [[RET]]
219221 ;
220222 %tmp0 = and <3 x i8> %x,
221223 %ret = icmp slt <3 x i8> %tmp0, %x