@@ -1547,61 +1547,6 @@ static bool optimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal,
1547
1547
return false ;
1548
1548
}
1549
1549
1550
- // / TryToAddRangeMetadata - At this point, we have learned that the only
1551
- // / two values ever stored into GV are its initializer and OtherVal. See if we
1552
- // / can annotate loads from it with range metadata describing this.
1553
- // / This exposes the values to other scalar optimizations.
1554
- static bool TryToAddRangeMetadata (GlobalVariable *GV, Constant *OtherVal) {
1555
- Type *GVElType = GV->getType ()->getElementType ();
1556
-
1557
- // If GVElType is already i1, it already has a minimal range. If the type of
1558
- // the GV is an FP value, pointer or vector, don't do this optimization
1559
- // because range metadata is currently only supported on scalar integers.
1560
- if (GVElType == Type::getInt1Ty (GV->getContext ()) ||
1561
- GVElType->isFloatingPointTy () ||
1562
- GVElType->isPointerTy () || GVElType->isVectorTy ())
1563
- return false ;
1564
-
1565
- // Walk the use list of the global seeing if all the uses are load or store.
1566
- // If there is anything else, bail out.
1567
- for (User *U : GV->users ())
1568
- if (!isa<LoadInst>(U) && !isa<StoreInst>(U))
1569
- return false ;
1570
-
1571
- Constant *InitVal = GV->getInitializer ();
1572
- assert (InitVal->getType () != Type::getInt1Ty (GV->getContext ()) &&
1573
- " No reason to add range metadata!" );
1574
-
1575
- // The MD_range metadata only supports absolute integer constants.
1576
- if (!isa<ConstantInt>(InitVal) || !isa<ConstantInt>(OtherVal))
1577
- return false ;
1578
-
1579
- DEBUG (dbgs () << " *** ADDING RANGE METADATA: " << *GV);
1580
-
1581
- for (Value::user_iterator I = GV->user_begin (), E = GV->user_end (); I != E; ++I){
1582
- Instruction *UI = cast<Instruction>(*I);
1583
- if (LoadInst *LI = dyn_cast<LoadInst>(UI)) {
1584
- // If we already have a range, don't add a new one, so that GlobalOpt
1585
- // terminates. In theory, we could merge the two ranges.
1586
- if (LI->getMetadata (LLVMContext::MD_range))
1587
- return false ;
1588
- // Add range metadata to the load. We have two possible values, and we
1589
- // need to create a half-open range. The range can wrap, so we can use
1590
- // either signed or unsigned; we pick signed because it might be prettier
1591
- // in common cases.
1592
- Constant *Cmp = ConstantExpr::getICmp (ICmpInst::ICMP_SLT, InitVal, OtherVal);
1593
- Constant *One = ConstantInt::get (LI->getType (), 1 );
1594
- SmallVector<Metadata *, 2 > NewOps;
1595
- NewOps.push_back (ConstantAsMetadata::get (ConstantExpr::getSelect (Cmp, InitVal, OtherVal)));
1596
- NewOps.push_back (ConstantAsMetadata::get (ConstantExpr::getAdd (ConstantExpr::getSelect (Cmp, OtherVal, InitVal), One)));
1597
- MDNode *MD = MDNode::get (LI->getContext (), NewOps);
1598
- LI->setMetadata (LLVMContext::MD_range, MD);
1599
- }
1600
- }
1601
-
1602
- return true ;
1603
- }
1604
-
1605
1550
// / At this point, we have learned that the only two values ever stored into GV
1606
1551
// / are its initializer and OtherVal. See if we can shrink the global into a
1607
1552
// / boolean and select between the two values whenever it is used. This exposes
@@ -1981,10 +1926,9 @@ static bool processInternalGlobal(
1981
1926
1982
1927
// Otherwise, if the global was not a boolean, we can shrink it to be a
1983
1928
// boolean.
1984
- // XXX EMSCRIPTEN - add range metadata instead
1985
1929
if (Constant *SOVConstant = dyn_cast<Constant>(GS.StoredOnceValue )) {
1986
1930
if (GS.Ordering == AtomicOrdering::NotAtomic) {
1987
- if (TryToAddRangeMetadata (GV, SOVConstant)) { // XXX EMSCRIPTEN
1931
+ if (TryToShrinkGlobalToBoolean (GV, SOVConstant)) {
1988
1932
++NumShrunkToBool;
1989
1933
return true ;
1990
1934
}
0 commit comments