Skip to content

Commit

Permalink
[reductions] Delete another piece of dead flag handling [NFC]
Browse files Browse the repository at this point in the history
The code claimed to handle nsw/nuw, but those aren't passed via builder state and the explicit IR construction just above never sets them.

The only case this bit of code is actually relevant for is FMF flags.  However, dropPoisonGeneratingFlags currently doesn't know about FMF at all, so this was a noop.  It's also unneeded, as the caller explicitly configures the flags on the builder before this call, and the flags on the individual ops should be controled by the intrinsic flags anyways.  If any of the flags aren't safe to propagate, the caller needs to make that change.
  • Loading branch information
preames committed Dec 9, 2021
1 parent 2204a7b commit 0d13f94
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions llvm/lib/Transforms/Utils/LoopUtils.cpp
Expand Up @@ -951,6 +951,13 @@ Value *llvm::getShuffleReduction(IRBuilderBase &Builder, Value *Src,
// round.
assert(isPowerOf2_32(VF) &&
"Reduction emission only supported for pow2 vectors!");
// Note: fast-math-flags flags are controlled by the builder configuration
// and are assumed to apply to all generated arithmetic instructions. Other
// poison generating flags (nsw/nuw/inbounds/inrange/exact) are not part
// of the builder configuration, and since they're not passed explicitly,
// will never be relevant here. Note that it would be generally unsound to
// propagate these from an intrinsic call to the expansion anyways as we/
// change the order of operations.
Value *TmpVec = Src;
SmallVector<int, 32> ShuffleMask(VF);
for (unsigned i = VF; i != 1; i >>= 1) {
Expand All @@ -964,19 +971,13 @@ Value *llvm::getShuffleReduction(IRBuilderBase &Builder, Value *Src,
Value *Shuf = Builder.CreateShuffleVector(TmpVec, ShuffleMask, "rdx.shuf");

if (Op != Instruction::ICmp && Op != Instruction::FCmp) {
// The builder propagates its fast-math-flags setting.
TmpVec = Builder.CreateBinOp((Instruction::BinaryOps)Op, TmpVec, Shuf,
"bin.rdx");
} else {
assert(RecurrenceDescriptor::isMinMaxRecurrenceKind(RdxKind) &&
"Invalid min/max");
TmpVec = createMinMaxOp(Builder, RdxKind, TmpVec, Shuf);
}

// We may compute the reassociated scalar ops in a way that does not
// preserve nsw/nuw etc. Conservatively, drop those flags.
if (auto *ReductionInst = dyn_cast<Instruction>(TmpVec))
ReductionInst->dropPoisonGeneratingFlags();
}
// The result is in the first element of the vector.
return Builder.CreateExtractElement(TmpVec, Builder.getInt32(0));
Expand Down

0 comments on commit 0d13f94

Please sign in to comment.