Skip to content

Commit 138384a

Browse files
address review
1 parent 5a7fee1 commit 138384a

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

llvm/lib/Target/AMDGPU/AMDGPUUniformIntrinsicCombine.cpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/// some instruction whose operand was previously recognized as statically
1313
/// uniform is later on no longer recognized as statically uniform. However, the
1414
/// semantics of how programs execute don't (and must not, for this precise
15-
/// reason[0]) care about static uniformity, they only ever care about dynamic
15+
/// reason) care about static uniformity, they only ever care about dynamic
1616
/// uniformity. And every instruction that's downstream and cares about dynamic
1717
/// uniformity must be convergent (and isel will introduce v_readfirstlane for
1818
/// them if their operands can't be proven statically uniform).
@@ -42,17 +42,7 @@ using namespace llvm::AMDGPU;
4242
using namespace llvm::PatternMatch;
4343

4444
/// Tracks uniformity of newly created instructions.
45-
/// Wraps a ValueMap so we can enforce consistent mark/erase usage.
46-
struct UniformityTracker : DenseMap<const Value *, bool> {
47-
/// Record that V has known uniformity.
48-
void mark(Value *V, bool IsUniform) { (*this)[V] = IsUniform; }
49-
50-
/// Erase V from the map if it is an instruction with no uses anymore.
51-
void eraseIfDead(Value *V) {
52-
if (auto *I = dyn_cast<Instruction>(V); I && I->use_empty())
53-
this->erase(V);
54-
}
55-
};
45+
using UniformityTracker = ValueMap<const Value *, bool>;
5646

5747
/// Wrapper for querying uniformity info that first checks new instructions.
5848
static bool isDivergentUseWithNew(const Use &U, const UniformityInfo &UI,
@@ -78,7 +68,6 @@ static bool optimizeUniformIntrinsic(IntrinsicInst &II,
7868
return false;
7969
LLVM_DEBUG(dbgs() << "Replacing " << II << " with " << *Src << '\n');
8070
II.replaceAllUsesWith(Src);
81-
Tracker.eraseIfDead(&II);
8271
II.eraseFromParent();
8372
return true;
8473
}
@@ -104,28 +93,24 @@ static bool optimizeUniformIntrinsic(IntrinsicInst &II,
10493
// Case: (icmp eq %ballot, 0) -> xor %ballot_arg, 1
10594
Instruction *NotOp =
10695
BinaryOperator::CreateNot(Src, "", ICmp->getIterator());
107-
Tracker.mark(NotOp, true); // NOT preserves uniformity
96+
Tracker[NotOp] = true; // NOT preserves uniformity
10897
LLVM_DEBUG(dbgs() << "Replacing ICMP_EQ: " << *NotOp << '\n');
10998
ICmp->replaceAllUsesWith(NotOp);
110-
Tracker.eraseIfDead(ICmp);
11199
ICmp->eraseFromParent();
112100
Changed = true;
113101
} else if (Pred == ICmpInst::ICMP_NE && match(OtherOp, m_Zero())) {
114102
// Case: (icmp ne %ballot, 0) -> %ballot_arg
115103
LLVM_DEBUG(dbgs() << "Replacing ICMP_NE with ballot argument: "
116104
<< *Src << '\n');
117105
ICmp->replaceAllUsesWith(Src);
118-
Tracker.eraseIfDead(ICmp);
119106
ICmp->eraseFromParent();
120107
Changed = true;
121108
}
122109
}
123110
}
124111
// Erase the intrinsic if it has no remaining uses.
125-
if (II.use_empty()) {
126-
Tracker.eraseIfDead(&II);
112+
if (II.use_empty())
127113
II.eraseFromParent();
128-
}
129114
return Changed;
130115
}
131116
default:

0 commit comments

Comments
 (0)