Skip to content

Commit 75cff98

Browse files
committed
Avoid elementwise testing for failed splats
Put the elementwise checks for fixed-vector elements in an else block after checking for splats so that fixed-vector splats do not get checked twice if they fail to be optimized in the first check.
1 parent 7b1b750 commit 75cff98

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6817,18 +6817,17 @@ Value *llvm::simplifyBinaryIntrinsic(Intrinsic::ID IID, Type *ReturnType,
68176817
return ConstantVector::getSplat(VTy->getElementCount(),
68186818
OptSplatVal.value().NewConstVal);
68196819
}
6820-
}
6821-
6822-
// Check elementwise whether we can optimize to either a constant value
6823-
// or return the LHS value. We cannot mix and match LHS + constant
6824-
// elements, as this would require inserting a new VectorShuffle
6825-
// instruction, which is not allowed in simplifyBinOp, so bail early if
6826-
// any element cannot be optimized, or if lhs vs const optimizations
6827-
// start to mismatch. However, we can turn undef/poison into the LHS
6828-
// value, so only bail if we need at least 1 non undef/poison RHS const.
6829-
bool CanOptimize = true;
6830-
bool AllConstValsAreUndef = true;
6831-
if (auto *FVty = dyn_cast<FixedVectorType>(VTy)) {
6820+
} else if (auto *FVty = dyn_cast<FixedVectorType>(VTy)) {
6821+
// Check elementwise whether we can optimize to either a constant
6822+
// value or return the LHS value. We cannot mix and match LHS +
6823+
// constant elements, as this would require inserting a new
6824+
// VectorShuffle instruction, which is not allowed in simplifyBinOp,
6825+
// so bail early if any element cannot be optimized, or if lhs vs
6826+
// const optimizations start to mismatch. However, we can turn
6827+
// undef/poison into the LHS value, so only bail if we need at least 1
6828+
// non undef/poison RHS const.
6829+
bool CanOptimize = true;
6830+
bool AllConstValsAreUndef = true;
68326831
unsigned NumElts = FVty->getNumElements();
68336832
// Storage to build up the constant return value (possible altered
68346833
// from the input RHS value by quieting NaNs)

0 commit comments

Comments
 (0)