[InstCombine] Don't crash when trying to take an element of a ConstantExpr.

Fixes PR27786.

llvm-svn: 269757
This commit is contained in:
Benjamin Kramer 2016-05-17 12:08:55 +00:00
parent 6c1d74a094
commit ca9a0fe2b9
2 changed files with 13 additions and 0 deletions

View File

@ -3132,6 +3132,9 @@ static ICmpInst *canonicalizeCmpWithConstant(ICmpInst &I) {
unsigned NumElts = Op1Type->getVectorNumElements(); unsigned NumElts = Op1Type->getVectorNumElements();
for (unsigned i = 0; i != NumElts; ++i) { for (unsigned i = 0; i != NumElts; ++i) {
Constant *Elt = Op1C->getAggregateElement(i); Constant *Elt = Op1C->getAggregateElement(i);
if (!Elt)
return nullptr;
if (isa<UndefValue>(Elt)) if (isa<UndefValue>(Elt))
continue; continue;
// Bail out if we can't determine if this constant is min/max or if we // Bail out if we can't determine if this constant is min/max or if we

View File

@ -181,3 +181,13 @@ define <2 x i1> @PR27756_2(<2 x i8> %a) {
ret <2 x i1> %cmp ret <2 x i1> %cmp
} }
@someglobal = global i32 0
define <2 x i1> @PR27786(<2 x i8> %a) {
; CHECK-LABEL: @PR27786(
; CHECK-NEXT: [[CMP:%.*]] = icmp sle <2 x i8> %a, bitcast (i16 ptrtoint (i32* @someglobal to i16) to <2 x i8>)
; CHECK-NEXT: ret <2 x i1> [[CMP]]
;
%cmp = icmp sle <2 x i8> %a, bitcast (i16 ptrtoint (i32* @someglobal to i16) to <2 x i8>)
ret <2 x i1> %cmp
}