Skip to content

Commit 13102f6

Browse files
committed
prevent div by 0
1 parent a9188ad commit 13102f6

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,20 +278,19 @@ static bool expandNormalizeIntrinsic(CallInst *Orig) {
278278
/* gen_crash_diag=*/false);
279279
}
280280

281-
Value *Multiplicand = Builder.CreateIntrinsic(EltTy, Intrinsic::dx_rsqrt,
282-
ArrayRef<Value *>{DotProduct},
283-
nullptr, "dx.rsqrt");
284-
285281
// verify that the length is non-zero
286-
// (if the reciprocal sqrt of the length is non-zero, then the length is
287-
// non-zero)
288-
if (auto *constantFP = dyn_cast<ConstantFP>(Multiplicand)) {
282+
// (if the dot product is non-zero, then the length is non-zero)
283+
if (auto *constantFP = dyn_cast<ConstantFP>(DotProduct)) {
289284
const APFloat &fpVal = constantFP->getValueAPF();
290285
if (fpVal.isZero())
291286
report_fatal_error(Twine("Invalid input vector: length is zero"),
292287
/* gen_crash_diag=*/false);
293288
}
294289

290+
Value *Multiplicand = Builder.CreateIntrinsic(EltTy, Intrinsic::dx_rsqrt,
291+
ArrayRef<Value *>{DotProduct},
292+
nullptr, "dx.rsqrt");
293+
295294
Value *MultiplicandVec = Builder.CreateVectorSplat(XVecSize, Multiplicand);
296295
Value *Result = Builder.CreateFMul(X, MultiplicandVec);
297296

0 commit comments

Comments
 (0)