@@ -7013,19 +7013,18 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) {
7013
7013
unsigned AS = LI->getPointerAddressSpace ();
7014
7014
Value *PO = LI->getPointerOperand ();
7015
7015
if (E->State == TreeEntry::Vectorize) {
7016
-
7017
7016
Value *VecPtr = Builder.CreateBitCast (PO, VecTy->getPointerTo (AS));
7017
+ NewLI = Builder.CreateAlignedLoad (VecTy, VecPtr, LI->getAlign ());
7018
7018
7019
7019
// The pointer operand uses an in-tree scalar so we add the new BitCast
7020
- // to ExternalUses list to make sure that an extract will be generated
7021
- // in the future.
7020
+ // or LoadInst to ExternalUses list to make sure that an extract will
7021
+ // be generated in the future.
7022
7022
if (TreeEntry *Entry = getTreeEntry (PO)) {
7023
7023
// Find which lane we need to extract.
7024
7024
unsigned FoundLane = Entry->findLaneForValue (PO);
7025
- ExternalUses.emplace_back (PO, cast<User>(VecPtr), FoundLane);
7025
+ ExternalUses.emplace_back (
7026
+ PO, PO != VecPtr ? cast<User>(VecPtr) : NewLI, FoundLane);
7026
7027
}
7027
-
7028
- NewLI = Builder.CreateAlignedLoad (VecTy, VecPtr, LI->getAlign ());
7029
7028
} else {
7030
7029
assert (E->State == TreeEntry::ScatterVectorize && " Unhandled state" );
7031
7030
Value *VecPtr = vectorizeTree (E->getOperand (0 ));
@@ -7058,17 +7057,18 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) {
7058
7057
Value *ScalarPtr = SI->getPointerOperand ();
7059
7058
Value *VecPtr = Builder.CreateBitCast (
7060
7059
ScalarPtr, VecValue->getType ()->getPointerTo (AS));
7061
- StoreInst *ST = Builder. CreateAlignedStore (VecValue, VecPtr,
7062
- SI->getAlign ());
7060
+ StoreInst *ST =
7061
+ Builder. CreateAlignedStore (VecValue, VecPtr, SI->getAlign ());
7063
7062
7064
- // The pointer operand uses an in-tree scalar, so add the new BitCast to
7065
- // ExternalUses to make sure that an extract will be generated in the
7066
- // future.
7063
+ // The pointer operand uses an in-tree scalar, so add the new BitCast or
7064
+ // StoreInst to ExternalUses to make sure that an extract will be
7065
+ // generated in the future.
7067
7066
if (TreeEntry *Entry = getTreeEntry (ScalarPtr)) {
7068
7067
// Find which lane we need to extract.
7069
7068
unsigned FoundLane = Entry->findLaneForValue (ScalarPtr);
7070
- ExternalUses.push_back (
7071
- ExternalUser (ScalarPtr, cast<User>(VecPtr), FoundLane));
7069
+ ExternalUses.push_back (ExternalUser (
7070
+ ScalarPtr, ScalarPtr != VecPtr ? cast<User>(VecPtr) : ST,
7071
+ FoundLane));
7072
7072
}
7073
7073
7074
7074
Value *V = propagateMetadata (ST, E->Scalars );
0 commit comments