This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] Let isGuaranteedNotToBeUndefOrPoison consider noundef
ClosedPublic

Authored by aqjune on Jul 14 2020, 1:14 AM.

Details

Diff Detail

Event Timeline

aqjune created this revision.Jul 14 2020, 1:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2020, 1:14 AM

Has little impact on compilation time on average:

(unit:sec.)
+-----------------------------------------------+---------+---------+----------+-------+---------+----------+
|                                               | compile |         |          | link  |         |          |
+-----------------------------------------------+---------+---------+----------+-------+---------+----------+
|                                               | base    | noundef | slowdown | base  | noundef | slowdown |
| CTMark/7zip/7zip-benchmark.test               | 89.55   | 89.45   | -0.11%   | 46.86 | 46.87   | 0.04%    |
| CTMark/Bullet/bullet.test                     | 63.06   | 62.84   | -0.35%   | 9.97  | 9.69    | -2.73%   |
| CTMark/ClamAV/clamscan.test                   | 26.89   | 26.88   | -0.05%   | 24.91 | 25.01   | 0.40%    |
| CTMark/SPASS/SPASS.test                       | 26.17   | 26.08   | -0.36%   | 19.68 | 19.70   | 0.10%    |
| CTMark/consumer-typeset/consumer-typeset.test | 19.69   | 19.63   | -0.28%   | 18.44 | 18.56   | 0.63%    |
| CTMark/kimwitu++/kc.test                      | 26.48   | 26.50   | 0.06%    | 14.59 | 14.34   | -1.76%   |
| CTMark/lencod/lencod.test                     | 34.46   | 34.42   | -0.13%   | 38.37 | 38.63   | 0.67%    |
| CTMark/mafft/pairlocalalign.test              | 16.20   | 16.17   | -0.18%   | 8.65  | 8.64    | -0.11%   |
| CTMark/sqlite3/sqlite3.test                   | 24.59   | 24.51   | -0.33%   | 24.52 | 24.52   | -0.02%   |
| CTMark/tramp3d-v4/tramp3d-v4.test             | 49.26   | 49.16   | -0.21%   | 35.74 | 35.71   | -0.09%   |
+-----------------------------------------------+---------+---------+----------+-------+---------+----------+
nikic added inline comments.Jul 14 2020, 9:32 AM
llvm/include/llvm/Analysis/ValueTracking.h
610

Why do we need this parameter? Padding only matters for the stored representation of a struct. For SSA struct values, the padding cannot be accessed.

llvm/lib/Analysis/ValueTracking.cpp
4792

Why are some of these checked outside the dyn_cast<Operator>(V) below?

aqjune updated this revision to Diff 278057.Jul 14 2020, 7:57 PM

Move relevant code snippets into if branch on dyn_cast<Operator>

aqjune marked 2 inline comments as done.Jul 14 2020, 8:02 PM

After this patch is accepted, I'll make a separate commit for tests so only diffs are updated.

llvm/include/llvm/Analysis/ValueTracking.h
610

It is because freeze can take an aggregate value.
I found that its behavior w.r.t aggregate values is not specified in LangRef, but I think it is good to make it freeze the paddings too because it guarantees that v = freeze(load p); store v, q will never have undef bits or poison in memory.
If this sounds good, I'll make a patch for this.

This patch adds support for noundef arguments and looking through more operations.

Maybe make it multiple patches then?

nikic added inline comments.Jul 15 2020, 12:35 AM
llvm/include/llvm/Analysis/ValueTracking.h
610

I don't think something like this can work under current IR semantics. Even if we take a simpler example like %v = freeze(load i1 %p); store %v, %q, the freeze will only freeze the i1 value, it does not do anything to the remaining 7 bits that are present in the store representation. It does make sure that a subsequent load i1 will not see undef/poison, but not that a load i8 won't. For the aggregate case, similarly, it does make sure that loading the same aggregate type will not have undef/poison (because padding does not matter for the SSA value), but does not make sure that loading an appropriately sized iN at the same location will not have undef/poison.

aqjune marked an inline comment as done.Jul 15 2020, 5:32 PM

Will split this patch into (1) noundef patch (2) use operator patch

llvm/include/llvm/Analysis/ValueTracking.h
610

Okay, that makes sense. There is no way to remove the 7-bit undef value when storing i1 value.

aqjune updated this revision to Diff 278351.Jul 15 2020, 6:58 PM

Leave noundef patch only

aqjune retitled this revision from [ValueTracking] Let isGuaranteedNotToBeUndefOrPoison consider noundef and more operations to [ValueTracking] Let isGuaranteedNotToBeUndefOrPoison consider noundef.Jul 15 2020, 6:58 PM
aqjune edited the summary of this revision. (Show Details)
nikic accepted this revision.Jul 16 2020, 9:27 AM

LG

llvm/lib/Analysis/ValueTracking.cpp
4763

This comment seems a bit out of context now that the IgnorePadding flag is gone.

This revision is now accepted and ready to land.Jul 16 2020, 9:27 AM
This revision was automatically updated to reflect the committed changes.