From 1c9f15426fb04d6601749da711f41af89869d494 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Wed, 2 Feb 2022 09:44:15 +0000 Subject: [PATCH] [GVN] Replace PointerIntPair with separate pointer & kind fields (NFC). After adding another value kind in 8a12cae862af, Value * pointers do not have enough available empty bits to store the kind (e.g. on ARM) To address this, the patch replaces the PointerIntPair with separate value and kind fields. --- llvm/lib/Transforms/Scalar/GVN.cpp | 46 ++++++++++++++++-------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp index 94c57f190c8a..c3008a689657 100644 --- a/llvm/lib/Transforms/Scalar/GVN.cpp +++ b/llvm/lib/Transforms/Scalar/GVN.cpp @@ -178,7 +178,7 @@ template <> struct DenseMapInfo { /// implicitly associated with a rematerialization point which is the /// location of the instruction from which it was formed. struct llvm::gvn::AvailableValue { - enum ValType { + enum class ValType { SimpleVal, // A simple offsetted value that is accessed. LoadVal, // A value produced by a load. MemIntrin, // A memory intrinsic which is loaded from. @@ -188,76 +188,78 @@ struct llvm::gvn::AvailableValue { // can be replace by a value select. }; - /// V - The value that is live out of the block. - PointerIntPair Val; + /// Val - The value that is live out of the block. + Value *Val; + /// Kind of the live-out value. + ValType Kind; /// Offset - The byte offset in Val that is interesting for the load query. unsigned Offset = 0; static AvailableValue get(Value *V, unsigned Offset = 0) { AvailableValue Res; - Res.Val.setPointer(V); - Res.Val.setInt(SimpleVal); + Res.Val = V; + Res.Kind = ValType::SimpleVal; Res.Offset = Offset; return Res; } static AvailableValue getMI(MemIntrinsic *MI, unsigned Offset = 0) { AvailableValue Res; - Res.Val.setPointer(MI); - Res.Val.setInt(MemIntrin); + Res.Val = MI; + Res.Kind = ValType::MemIntrin; Res.Offset = Offset; return Res; } static AvailableValue getLoad(LoadInst *Load, unsigned Offset = 0) { AvailableValue Res; - Res.Val.setPointer(Load); - Res.Val.setInt(LoadVal); + Res.Val = Load; + Res.Kind = ValType::LoadVal; Res.Offset = Offset; return Res; } static AvailableValue getUndef() { AvailableValue Res; - Res.Val.setPointer(nullptr); - Res.Val.setInt(UndefVal); + Res.Val = nullptr; + Res.Kind = ValType::UndefVal; Res.Offset = 0; return Res; } static AvailableValue getSelect(SelectInst *Sel) { AvailableValue Res; - Res.Val.setPointer(Sel); - Res.Val.setInt(SelectVal); + Res.Val = Sel; + Res.Kind = ValType::SelectVal; Res.Offset = 0; return Res; } - bool isSimpleValue() const { return Val.getInt() == SimpleVal; } - bool isCoercedLoadValue() const { return Val.getInt() == LoadVal; } - bool isMemIntrinValue() const { return Val.getInt() == MemIntrin; } - bool isUndefValue() const { return Val.getInt() == UndefVal; } - bool isSelectValue() const { return Val.getInt() == SelectVal; } + bool isSimpleValue() const { return Kind == ValType::SimpleVal; } + bool isCoercedLoadValue() const { return Kind == ValType::LoadVal; } + bool isMemIntrinValue() const { return Kind == ValType::MemIntrin; } + bool isUndefValue() const { return Kind == ValType::UndefVal; } + bool isSelectValue() const { return Kind == ValType::SelectVal; } Value *getSimpleValue() const { assert(isSimpleValue() && "Wrong accessor"); - return Val.getPointer(); + return Val; } LoadInst *getCoercedLoadValue() const { assert(isCoercedLoadValue() && "Wrong accessor"); - return cast(Val.getPointer()); + return cast(Val); } MemIntrinsic *getMemIntrinValue() const { assert(isMemIntrinValue() && "Wrong accessor"); - return cast(Val.getPointer()); + return cast(Val); } SelectInst *getSelectValue() const { assert(isSelectValue() && "Wrong accessor"); - return cast(Val.getPointer()); + return cast(Val); } /// Emit code at the specified insertion point to adjust the value defined