[llvm] 0e6257f - SSAUpdater: use poison instead of undef in phi entries for unreachable predecessors
Nuno Lopes via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 30 03:52:06 PDT 2024
Author: Nuno Lopes
Date: 2024-06-30T11:51:30+01:00
New Revision: 0e6257fbc2a1e0ccccec6a58d780ef5367047120
URL: https://github.com/llvm/llvm-project/commit/0e6257fbc2a1e0ccccec6a58d780ef5367047120
DIFF: https://github.com/llvm/llvm-project/commit/0e6257fbc2a1e0ccccec6a58d780ef5367047120.diff
LOG: SSAUpdater: use poison instead of undef in phi entries for unreachable predecessors
Added:
Modified:
llvm/include/llvm/Transforms/Utils/SSAUpdaterImpl.h
llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
llvm/lib/CodeGen/MachineSSAUpdater.cpp
llvm/lib/Transforms/Utils/SSAUpdater.cpp
llvm/test/CodeGen/AMDGPU/promote-alloca-non-constant-index.ll
llvm/test/Transforms/GVN/pr48805.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/Utils/SSAUpdaterImpl.h b/llvm/include/llvm/Transforms/Utils/SSAUpdaterImpl.h
index a3e5ac3ac19d4..28ff6c4c7927d 100644
--- a/llvm/include/llvm/Transforms/Utils/SSAUpdaterImpl.h
+++ b/llvm/include/llvm/Transforms/Utils/SSAUpdaterImpl.h
@@ -96,7 +96,7 @@ class SSAUpdaterImpl {
// Special case: bail out if BB is unreachable.
if (BlockList.size() == 0) {
- ValT V = Traits::GetUndefVal(BB, Updater);
+ ValT V = Traits::GetPoisonVal(BB, Updater);
(*AvailableVals)[BB] = V;
return V;
}
@@ -251,9 +251,9 @@ class SSAUpdaterImpl {
for (unsigned p = 0; p != Info->NumPreds; ++p) {
BBInfo *Pred = Info->Preds[p];
- // Treat an unreachable predecessor as a definition with 'undef'.
+ // Treat an unreachable predecessor as a definition with 'poison'.
if (Pred->BlkNum == 0) {
- Pred->AvailableVal = Traits::GetUndefVal(Pred->BB, Updater);
+ Pred->AvailableVal = Traits::GetPoisonVal(Pred->BB, Updater);
(*AvailableVals)[Pred->BB] = Pred->AvailableVal;
Pred->DefBB = Pred;
Pred->BlkNum = PseudoEntry->BlkNum;
diff --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
index 481d9e341da37..555cbb7a507f4 100644
--- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
+++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
@@ -3907,7 +3907,7 @@ class LDVSSAUpdater {
DenseMap<BlockValueNum, LDVSSAPhi *> PHIs;
/// Map of which blocks generate Undef values -- blocks that are not
/// dominated by any Def.
- DenseMap<MachineBasicBlock *, BlockValueNum> UndefMap;
+ DenseMap<MachineBasicBlock *, BlockValueNum> PoisonMap;
/// Map of machine blocks to our own records of them.
DenseMap<MachineBasicBlock *, LDVSSABlock *> BlockMap;
/// Machine location where any PHI must occur.
@@ -3923,7 +3923,7 @@ class LDVSSAUpdater {
delete Block.second;
PHIs.clear();
- UndefMap.clear();
+ PoisonMap.clear();
BlockMap.clear();
}
@@ -4017,15 +4017,15 @@ template <> class SSAUpdaterTraits<LDVSSAUpdater> {
Preds->push_back(BB->Updater.getSSALDVBlock(Pred));
}
- /// GetUndefVal - Normally creates an IMPLICIT_DEF instruction with a new
+ /// GetPoisonVal - Normally creates an IMPLICIT_DEF instruction with a new
/// register. For LiveDebugValues, represents a block identified as not having
/// any DBG_PHI predecessors.
- static BlockValueNum GetUndefVal(LDVSSABlock *BB, LDVSSAUpdater *Updater) {
+ static BlockValueNum GetPoisonVal(LDVSSABlock *BB, LDVSSAUpdater *Updater) {
// Create a value number for this block -- it needs to be unique and in the
- // "undef" collection, so that we know it's not real. Use a number
+ // "poison" collection, so that we know it's not real. Use a number
// representing a PHI into this block.
BlockValueNum Num = ValueIDNum(BB->BB.getNumber(), 0, Updater->Loc).asU64();
- Updater->UndefMap[&BB->BB] = Num;
+ Updater->PoisonMap[&BB->BB] = Num;
return Num;
}
@@ -4188,7 +4188,7 @@ std::optional<ValueIDNum> InstrRefBasedLDV::resolveDbgPHIsImpl(
// Are all these things actually defined?
for (auto &PHIIt : PHI->IncomingValues) {
// Any undef input means DBG_PHIs didn't dominate the use point.
- if (Updater.UndefMap.contains(&PHIIt.first->BB))
+ if (Updater.PoisonMap.contains(&PHIIt.first->BB))
return std::nullopt;
ValueIDNum ValueToCheck;
diff --git a/llvm/lib/CodeGen/MachineSSAUpdater.cpp b/llvm/lib/CodeGen/MachineSSAUpdater.cpp
index 5b21c5653b46b..ffe1df4ec1ce8 100644
--- a/llvm/lib/CodeGen/MachineSSAUpdater.cpp
+++ b/llvm/lib/CodeGen/MachineSSAUpdater.cpp
@@ -306,11 +306,11 @@ class SSAUpdaterTraits<MachineSSAUpdater> {
append_range(*Preds, BB->predecessors());
}
- /// GetUndefVal - Create an IMPLICIT_DEF instruction with a new register.
+ /// GetPoisonVal - Create an IMPLICIT_DEF instruction with a new register.
/// Add it into the specified block and return the register.
- static Register GetUndefVal(MachineBasicBlock *BB,
+ static Register GetPoisonVal(MachineBasicBlock *BB,
MachineSSAUpdater *Updater) {
- // Insert an implicit_def to represent an undef value.
+ // Insert an implicit_def to represent a poison value.
MachineInstr *NewDef =
InsertNewDef(TargetOpcode::IMPLICIT_DEF, BB, BB->getFirstNonPHI(),
Updater->RegAttrs, Updater->MRI, Updater->TII);
diff --git a/llvm/lib/Transforms/Utils/SSAUpdater.cpp b/llvm/lib/Transforms/Utils/SSAUpdater.cpp
index ca5bfb8de08ad..7fd3e51e141f3 100644
--- a/llvm/lib/Transforms/Utils/SSAUpdater.cpp
+++ b/llvm/lib/Transforms/Utils/SSAUpdater.cpp
@@ -136,9 +136,9 @@ Value *SSAUpdater::GetValueInMiddleOfBlock(BasicBlock *BB) {
}
}
- // If there are no predecessors, just return undef.
+ // If there are no predecessors, just return poison.
if (PredValues.empty())
- return UndefValue::get(ProtoType);
+ return PoisonValue::get(ProtoType);
// Otherwise, if all the merged values are the same, just use it.
if (SingularValue)
@@ -307,10 +307,10 @@ class SSAUpdaterTraits<SSAUpdater> {
append_range(*Preds, predecessors(BB));
}
- /// GetUndefVal - Get an undefined value of the same type as the value
+ /// GetPoisonVal - Get a poison value of the same type as the value
/// being handled.
- static Value *GetUndefVal(BasicBlock *BB, SSAUpdater *Updater) {
- return UndefValue::get(Updater->ProtoType);
+ static Value *GetPoisonVal(BasicBlock *BB, SSAUpdater *Updater) {
+ return PoisonValue::get(Updater->ProtoType);
}
/// CreateEmptyPHI - Create a new PHI instruction in the specified block.
diff --git a/llvm/test/CodeGen/AMDGPU/promote-alloca-non-constant-index.ll b/llvm/test/CodeGen/AMDGPU/promote-alloca-non-constant-index.ll
index 272a9ebe536c9..5e16efa89eb1c 100644
--- a/llvm/test/CodeGen/AMDGPU/promote-alloca-non-constant-index.ll
+++ b/llvm/test/CodeGen/AMDGPU/promote-alloca-non-constant-index.ll
@@ -14,7 +14,7 @@ define amdgpu_kernel void @non_constant_index(i32 %arg) {
; CHECK: bb2:
; CHECK-NEXT: br label [[BB3:%.*]]
; CHECK: bb3:
-; CHECK-NEXT: [[PROMOTEALLOCA:%.*]] = phi <2 x float> [ [[TMP2:%.*]], [[BB3]] ], [ undef, [[BB2:%.*]] ]
+; CHECK-NEXT: [[PROMOTEALLOCA:%.*]] = phi <2 x float> [ [[TMP2:%.*]], [[BB3]] ], [ poison, [[BB2:%.*]] ]
; CHECK-NEXT: [[TMP0:%.*]] = insertelement <2 x float> [[PROMOTEALLOCA]], float 0.000000e+00, i32 [[ARG]]
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[ARG]], 1
; CHECK-NEXT: [[TMP2]] = insertelement <2 x float> [[TMP0]], float 0.000000e+00, i32 [[TMP1]]
diff --git a/llvm/test/Transforms/GVN/pr48805.ll b/llvm/test/Transforms/GVN/pr48805.ll
index e3fdc280255fa..dc0159327e7c7 100644
--- a/llvm/test/Transforms/GVN/pr48805.ll
+++ b/llvm/test/Transforms/GVN/pr48805.ll
@@ -22,7 +22,7 @@ define i64 @test(ptr %p) {
; CHECK-NEXT: [[P1:%.*]] = load ptr, ptr [[A2]], align 8
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
-; CHECK-NEXT: [[RES:%.*]] = phi i64 [ [[RES_PRE]], [[ENTRY_EXIT_CRIT_EDGE]] ], [ undef, [[IF]] ]
+; CHECK-NEXT: [[RES:%.*]] = phi i64 [ [[RES_PRE]], [[ENTRY_EXIT_CRIT_EDGE]] ], [ poison, [[IF]] ]
; CHECK-NEXT: store ptr @willreturn, ptr [[P]], align 8
; CHECK-NEXT: tail call void @willreturn()
; CHECK-NEXT: ret i64 [[RES]]
More information about the llvm-commits
mailing list