Page MenuHomePhabricator

[CVP} Replace SExt with ZExt if the input is known-non-negative
ClosedPublic

Authored by lebedev.ri on Oct 8 2019, 11:15 AM.

Details

Summary

zero-extension is far more friendly for further analysis.
While this doesn't directly help with the shift-by-signext problem, this is not unrelated.

This has the following effect on test-suite (numbers collected after the finish of middle-end module pass manager):

Statisticoldnewdeltapercent change
correlated-value-propagation.NumSExt060266026+100.00%
instcount.NumAddInst272860271283-1577-0.58%
instcount.NumAllocaInst2722727226-10.00%
instcount.NumAndInst6350263320-182-0.29%
instcount.NumAShrInst1349813407-91-0.67%
instcount.NumAtomicCmpXchgInst1159115900.00%
instcount.NumAtomicRMWInst5036503600.00%
instcount.NumBitCastInst672482672353-129-0.02%
instcount.NumBrInst702768702195-573-0.08%
instcount.NumCallInst518285518205-80-0.02%
instcount.NumExtractElementInst184811848210.01%
instcount.NumExtractValueInst1829018288-2-0.01%
instcount.NumFAddInst139035138963-72-0.05%
instcount.NumFCmpInst1035810348-10-0.10%
instcount.NumFDivInst3031030302-8-0.03%
instcount.NumFenceInst38738700.00%
instcount.NumFMulInst9387393806-67-0.07%
instcount.NumFPExtInst71487144-4-0.06%
instcount.NumFPToSIInst28232838150.53%
instcount.NumFPToUIInst1251125100.00%
instcount.NumFPTruncInst21952191-4-0.18%
instcount.NumFSubInst9210992103-6-0.01%
instcount.NumGetElementPtrInst12214231219157-2266-0.19%
instcount.NumICmpInst479140478929-211-0.04%
instcount.NumIndirectBrInst2200.00%
instcount.NumInsertElementInst660896609450.01%
instcount.NumInsertValueInst20322030-2-0.10%
instcount.NumIntToPtrInst196411964100.00%
instcount.NumInvokeInst2178921788-10.00%
instcount.NumLandingPadInst120511205100.00%
instcount.NumLoadInst880079878673-1406-0.16%
instcount.NumLShrInst259192592120.01%
instcount.NumMulInst424164241710.00%
instcount.NumOrInst100826100576-250-0.25%
instcount.NumPHIInst315118314092-1026-0.33%
instcount.NumPtrToIntInst159331593960.04%
instcount.NumResumeInst2156215600.00%
instcount.NumRetInst8448584484-10.00%
instcount.NumSDivInst85998597-2-0.02%
instcount.NumSelectInst45577459133360.74%
instcount.NumSExtInst8402678278-5748-6.84%
instcount.NumShlInst3979639726-70-0.18%
instcount.NumShuffleVectorInst100272100292200.02%
instcount.NumSIToFPInst2913129113-18-0.06%
instcount.NumSRemInst1543154300.00%
instcount.NumStoreInst805394804351-1043-0.13%
instcount.NumSubInst6133761414770.13%
instcount.NumSwitchInst85278524-3-0.04%
instcount.NumTruncInst6052360484-39-0.06%
instcount.NumUDivInst2381238100.00%
instcount.NumUIToFPInst5549554900.00%
instcount.NumUnreachableInst9855985500.00%
instcount.NumURemInst1305130500.00%
instcount.NumXorInst1023010081-149-1.46%
instcount.NumZExtInst6035366840648710.75%
instcount.TotalBlocks829582829004-578-0.07%
instcount.TotalFuncs8381883817-10.00%
instcount.TotalInsts73165747308483-8091-0.11%

TLDR: we produce -0.11% less instructions, -6.84% less sext, +10.75% more zext.
To be noted, clearly, not all new zext's are produced by this fold.

(And now i guess it might have been interesting to measure this for D68103 :S)

Diff Detail

Event Timeline

lebedev.ri created this revision.Oct 8 2019, 11:15 AM
nikic accepted this revision.Oct 8 2019, 12:08 PM

LGTM. Especially as we already have the corresponding ashr to lshr transform, this seems like an obvious extension.

llvm/test/Transforms/CorrelatedValuePropagation/sext.ll
46

nit: n >= 0

This revision is now accepted and ready to land.Oct 8 2019, 12:08 PM

LGTM. Especially as we already have the corresponding ashr to lshr transform, this seems like an obvious extension.

Thank you for the review.

This revision was automatically updated to reflect the committed changes.