@@ -403,7 +403,8 @@ class GenXSimdCFConformance {
403
403
Value *findLoweredEMValue (Value *Val);
404
404
Value *buildLoweringViaGetEM (Value *Val, Instruction *InsertBefore);
405
405
Value *getGetEMLoweredValue (Value *Val, Instruction *InsertBefore);
406
- Value *lowerEVIUse (ExtractValueInst *EVI, Instruction *User);
406
+ Value *lowerEVIUse (ExtractValueInst *EVI, Instruction *User,
407
+ BasicBlock *PhiPredBlock = nullptr );
407
408
Value *lowerPHIUse (PHINode *PN, SetVector<Value *> &ToRemove);
408
409
Value *lowerArgumentUse (Argument *Arg);
409
410
Value *insertCond (Value *OldVal, Value *NewVal, const Twine &Name, Instruction *InsertBefore, const DebugLoc &DL);
@@ -742,7 +743,7 @@ Value *GenXSimdCFConformance::findGotoJoinVal(int Cat, BasicBlock *Loc, Instruct
742
743
743
744
LLVM_DEBUG (dbgs () << " Entering " << Loc->getName () << " \n " );
744
745
745
- // Check if value were found before
746
+ // Check if value was found before
746
747
auto ResIt = foundVals.find (Loc);
747
748
if (ResIt != foundVals.end ())
748
749
return ResIt->second ;
@@ -2976,7 +2977,8 @@ Value *GenXSimdCFConformance::getGetEMLoweredValue(Value *Val,
2976
2977
* EM is being lowered via genx_simdcf_get_em intrinsic.
2977
2978
*/
2978
2979
Value *GenXSimdCFConformance::lowerEVIUse (ExtractValueInst *EVI,
2979
- Instruction *User) {
2980
+ Instruction *User,
2981
+ BasicBlock *PhiPredBlock) {
2980
2982
LLVM_DEBUG (dbgs () << " Lowering EVI use:\n " << *EVI << " \n " );
2981
2983
2982
2984
CallInst *GotoJoin = dyn_cast<CallInst>(EVI->getOperand (0 ));
@@ -2996,16 +2998,26 @@ Value *GenXSimdCFConformance::lowerEVIUse(ExtractValueInst *EVI,
2996
2998
BasicBlock *DefBB = GotoJoin->getParent ();
2997
2999
BasicBlock *TrueBlock = DefBB->getTerminator ()->getSuccessor (0 );
2998
3000
BasicBlock *FalseBlock = DefBB->getTerminator ()->getSuccessor (1 );
3001
+ BasicBlock *Loc = PhiPredBlock ? PhiPredBlock : User->getParent ();
2999
3002
3003
+ // GetEM is removed later if redundant.
3000
3004
Value *TrueVal = Constant::getNullValue (EVI->getType ());
3001
3005
Value *FalseVal = getGetEMLoweredValue (EVI, FalseBlock->getFirstNonPHI ());
3002
3006
3007
+ // Early return for direct phi true edge: lowered value is zeroed
3008
+ if (PhiPredBlock == DefBB && TrueBlock == User->getParent ()) {
3009
+ IGC_ASSERT (PhiPredBlock);
3010
+ IGC_ASSERT_MESSAGE (FalseBlock != TrueBlock,
3011
+ " Crit edge should be inserted earlier!" );
3012
+ return TrueVal;
3013
+ }
3014
+
3003
3015
std::map<BasicBlock *, Value *> foundVals;
3004
3016
BasicBlockEdge TrueEdge (DefBB, TrueBlock);
3005
3017
BasicBlockEdge FalseEdge (DefBB, FalseBlock);
3006
3018
3007
- return findGotoJoinVal (RegCategory::EM, User-> getParent () , EVI, TrueEdge,
3008
- FalseEdge, TrueVal, FalseVal, foundVals);
3019
+ return findGotoJoinVal (RegCategory::EM, Loc , EVI, TrueEdge, FalseEdge ,
3020
+ TrueVal, FalseVal, foundVals);
3009
3021
}
3010
3022
3011
3023
// Non-branching case: must be join. Insert get_em right after join's EM
@@ -3022,8 +3034,11 @@ Value *GenXSimdCFConformance::lowerEVIUse(ExtractValueInst *EVI,
3022
3034
* lowerPHIUse : lower PHI use.
3023
3035
*
3024
3036
* EM is being lowered via genx_simdcf_get_em intrinsic.
3025
- * When PHI lowering is needed, we have to lower all incoming
3026
- * values. Lowered phis are also stored in LoweredPhisMap to
3037
+ * This intrinsic is inserted right after the phis in current BB
3038
+ * in case of non-join block. For join blocks, the full PHI lowering
3039
+ * is performed: we have to lower all incoming values.
3040
+ *
3041
+ * Lowered phis are also stored in LoweredPhisMap to
3027
3042
* prevent redundant lowerings.
3028
3043
*/
3029
3044
Value *GenXSimdCFConformance::lowerPHIUse (PHINode *PN,
@@ -3035,6 +3050,14 @@ Value *GenXSimdCFConformance::lowerPHIUse(PHINode *PN,
3035
3050
return FoundVal;
3036
3051
}
3037
3052
3053
+ if (!GotoJoin::isJoinLabel (PN->getParent ())) {
3054
+ auto res = getGetEMLoweredValue (PN, PN->getParent ()->getFirstNonPHI ());
3055
+ LLVM_DEBUG (dbgs () << " Created " << *res << " \n " );
3056
+ return res;
3057
+ }
3058
+
3059
+ LLVM_DEBUG (dbgs () << " Performing full lowering\n " );
3060
+
3038
3061
// Clone phi and store it as lowered value.
3039
3062
auto *newPN = cast<PHINode>(PN->clone ());
3040
3063
newPN->insertAfter (PN);
@@ -3081,7 +3104,10 @@ void GenXSimdCFConformance::replaceUseWithLoweredEM(Instruction *Val, unsigned o
3081
3104
Value *LoweredEM = nullptr ;
3082
3105
3083
3106
if (auto *EVI = dyn_cast<ExtractValueInst>(EM)) {
3084
- LoweredEM = lowerEVIUse (EVI, Val);
3107
+ BasicBlock *PhiPredBlock = nullptr ;
3108
+ if (auto *PN = dyn_cast<PHINode>(Val))
3109
+ PhiPredBlock = PN->getIncomingBlock (operandNo);
3110
+ LoweredEM = lowerEVIUse (EVI, Val, PhiPredBlock);
3085
3111
} else if (auto *SVI = dyn_cast<ShuffleVectorInst>(EM)) {
3086
3112
// Shuffle vector: go through it and lower its pred.
3087
3113
// All changes will be applied here.
0 commit comments