- SmallVector<Constant *, 16> Elts;
- for (unsigned i = 0; i != NumElts; ++i) {
- Constant *FC = ConstantFoldCompareInstruction(pred, LHS->getOperand(i),
- RHS->getOperand(i));
- if (ConstantInt *FCI = dyn_cast_or_null<ConstantInt>(FC)) {
- if (FCI->getZExtValue())
- Elts.push_back(ConstantInt::getAllOnesValue(REltTy));
- else
- Elts.push_back(ConstantInt::get(REltTy, 0ULL));
- } else if (FC && isa<UndefValue>(FC)) {
- Elts.push_back(UndefValue::get(REltTy));
- } else {
- break;
+ // See if we can fold the element-wise comparison of the LHS and RHS.
+ SmallVector<Constant *, 16> LHSElts, RHSElts;
+ LHS->getVectorElements(LHSElts);
+ RHS->getVectorElements(RHSElts);
+
+ if (!LHSElts.empty() && !RHSElts.empty()) {
+ SmallVector<Constant *, 16> Elts;
+ for (unsigned i = 0; i != NumElts; ++i) {
+ Constant *FC = ConstantFoldCompareInstruction(pred, LHSElts[i],
+ RHSElts[i]);
+ if (ConstantInt *FCI = dyn_cast_or_null<ConstantInt>(FC)) {
+ if (FCI->getZExtValue())
+ Elts.push_back(ConstantInt::getAllOnesValue(REltTy));
+ else
+ Elts.push_back(ConstantInt::get(REltTy, 0ULL));
+ } else if (FC && isa<UndefValue>(FC)) {
+ Elts.push_back(UndefValue::get(REltTy));
+ } else {
+ break;
+ }