Skip to content

Commit 16e5b14

Browse files
committed
Address reviewer comments
1 parent 32096e1 commit 16e5b14

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

llvm/include/llvm/Target/GlobalISel/Combine.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def idempotent_prop : GICombineRule<
222222

223223
// Convert freeze(Op(Op0, NonPoisonOps...)) to Op(freeze(Op0), NonPoisonOps...)
224224
// when Op0 is not guaranteed non-poison
225-
def push_freeze_to_prevent_poison_propagation : GICombineRule<
225+
def push_freeze_to_prevent_poison_from_propagating : GICombineRule<
226226
(defs root:$root, build_fn_matchinfo:$matchinfo),
227227
(match (G_FREEZE $dst, $src):$root,
228228
[{ return !isGuaranteedNotToBePoison(${src}.getReg(), MRI) && Helper.matchFreezeOfSingleMaybePoisonOperand(*${root}, ${matchinfo}); }]),
@@ -1721,7 +1721,7 @@ def all_combines : GICombineGroup<[trivial_combines, vector_ops_combines,
17211721
fsub_to_fneg, commute_constant_to_rhs, match_ands, match_ors,
17221722
combine_concat_vector, double_icmp_zero_and_or_combine, match_addos,
17231723
sext_trunc, zext_trunc, combine_shuffle_concat,
1724-
push_freeze_to_prevent_poison_propagation]>;
1724+
push_freeze_to_prevent_poison_from_propagating]>;
17251725

17261726
// A combine group used to for prelegalizer combiners at -O0. The combines in
17271727
// this group have been selected based on experiments to balance code size and

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,22 @@ void CombinerHelper::applyCombineCopy(MachineInstr &MI) {
225225

226226
bool CombinerHelper::matchFreezeOfSingleMaybePoisonOperand(
227227
MachineInstr &MI, BuildFnTy &MatchInfo) {
228-
// Ported from InstCombinerImpl::pushFreezeToPreventPoisonFromPropagating
228+
// Ported from InstCombinerImpl::pushFreezeToPreventPoisonFromPropagating.
229229
Register DstOp = MI.getOperand(0).getReg();
230230
Register OrigOp = MI.getOperand(1).getReg();
231231

232232
if (!MRI.hasOneNonDBGUse(OrigOp))
233233
return false;
234234

235235
MachineInstr *OrigDef = MRI.getUniqueVRegDef(OrigOp);
236-
// Avoid trying to fold G_PHI and G_UNMERGE_VALUES.
236+
// Even if only a single operand of the PHI is not guaranteed non-poison,
237+
// moving freeze() backwards across a PHI can cause optimization issues for
238+
// other users of that operand.
239+
//
240+
// Moving freeze() from one of the output registers of a G_UNMERGE_VALUES to
241+
// the source register is unprofitable because it makes the freeze() more
242+
// strict than is necessary (it would affect the whole register instead of
243+
// just the subreg being frozen).
237244
if (OrigDef->isPHI() || isa<GUnmerge>(OrigDef))
238245
return false;
239246

@@ -243,7 +250,6 @@ bool CombinerHelper::matchFreezeOfSingleMaybePoisonOperand(
243250

244251
std::optional<MachineOperand> MaybePoisonOperand;
245252
for (MachineOperand &Operand : OrigDef->uses()) {
246-
// Avoid working on non-register operands.
247253
if (!Operand.isReg())
248254
return false;
249255

0 commit comments

Comments
 (0)