This is an archive of the discontinued LLVM Phabricator instance.

Handle IntToPtr in isBytewiseValue
ClosedPublic

Authored by vitalybuka on Jun 28 2019, 5:16 PM.

Details

Summary

This helps with more efficient use of memset for pattern initialization

From @pcc prototype for -ftrivial-auto-var-init=pattern optimizations

Binary size change on CTMark, (with -fuse-ld=lld -Wl,--icf=all, similar results with default linker options)

                   master           patch      diff
Os           8.238864e+05    8.238864e+05       0.0 
O3           1.054797e+06    1.054797e+06       0.0 
Os zero      8.292384e+05    8.292384e+05       0.0 
O3 zero      1.062626e+06    1.062626e+06       0.0 
Os pattern   8.579712e+05    8.338048e+05 -0.030299 
O3 pattern   1.090502e+06    1.067574e+06 -0.020481

Zero vs Pattern on master

               zero       pattern      diff
Os     8.292384e+05  8.579712e+05  0.036578 
O3     1.062626e+06  1.090502e+06  0.025124

Zero vs Pattern with the patch

               zero       pattern      diff
Os     8.292384e+05  8.338048e+05  0.003333 
O3     1.062626e+06  1.067574e+06  0.003193

Improved only for -m64. -m32 is not improved.

Diff Detail

Repository
rL LLVM

Event Timeline

vitalybuka created this revision.Jun 28 2019, 5:16 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 28 2019, 5:16 PM
vitalybuka edited the summary of this revision. (Show Details)Jul 10 2019, 4:01 PM
vitalybuka edited the summary of this revision. (Show Details)Jul 10 2019, 6:16 PM
vitalybuka edited the summary of this revision. (Show Details)Jul 10 2019, 6:19 PM
vitalybuka edited the summary of this revision. (Show Details)Jul 10 2019, 6:46 PM
eugenis accepted this revision.Jul 11 2019, 2:00 PM

LGTM

This revision is now accepted and ready to land.Jul 11 2019, 2:00 PM
vitalybuka marked an inline comment as done.Jul 11 2019, 2:05 PM
vitalybuka added inline comments.
llvm/lib/Analysis/ValueTracking.cpp
3222 ↗(On Diff #207180)

@pcc BTW, your original patch just gave up on size mismatch
Something like:

if (auto *CE = dyn_cast<ConstantExpr>(C)) {
    if (CE->getOpcode() == Instruction::IntToPtr &&
        cast<IntegerType>(CE->getOperand(0)->getType())->getBitWidth() ==
            DL.getPointerSizeInBits(
                cast<PointerType>(CE->getType())->getAddressSpace())) {
      return isBytewiseValue(CE->getOperand(0), DL);
    }
    return nullptr;
  }

Both versions affect binary size about the same.

This revision was automatically updated to reflect the committed changes.