|
38 | 38 | #include <memory> |
39 | 39 |
|
40 | 40 | #include "ir/element-utils.h" |
| 41 | +#include "ir/find_all.h" |
41 | 42 | #include "ir/intrinsics.h" |
42 | 43 | #include "ir/module-utils.h" |
43 | 44 | #include "ir/subtypes.h" |
@@ -492,11 +493,36 @@ struct Analyzer { |
492 | 493 | for (Index i = 0; i < new_->operands.size(); i++) { |
493 | 494 | auto* operand = new_->operands[i]; |
494 | 495 | auto structField = StructField{type, i}; |
495 | | - if (readStructFields.count(structField) || |
496 | | - EffectAnalyzer(options, *module, operand).hasSideEffects()) { |
497 | | - // This data can be read, so just walk it. Or, this has side effects, |
498 | | - // which is tricky to reason about - the side effects must happen even |
499 | | - // if we never read the struct field - so give up and consider it used. |
| 496 | + |
| 497 | + // If this struct field has already been read, then we should use the |
| 498 | + // contents there now. |
| 499 | + auto useOperandNow = readStructFields.count(structField); |
| 500 | + |
| 501 | + // Side effects are tricky to reason about - the side effects must happen |
| 502 | + // even if we never read the struct field - so give up and consider it |
| 503 | + // used. |
| 504 | + if (!useOperandNow) { |
| 505 | + useOperandNow = |
| 506 | + EffectAnalyzer(options, *module, operand).hasSideEffects(); |
| 507 | + } |
| 508 | + |
| 509 | + // We must handle the call.without.effects intrinsic here in a special |
| 510 | + // manner. That intrinsic is reported as having no side effects in |
| 511 | + // EffectAnalyzer, but even though for optimization purposes we can ignore |
| 512 | + // effects, the called code *is* actually reached, and it might have side |
| 513 | + // effects. In other words, the point of the intrinsic is to temporarily |
| 514 | + // ignore those effects during one phase of optimization. Or, put another |
| 515 | + // way, the intrinsic lets us ignore the effects of computing some value, |
| 516 | + // but we do still need to compute that value if it is received and used |
| 517 | + // (if it is not received and used, other passes will remove it). |
| 518 | + if (!useOperandNow) { |
| 519 | + // To detect this, look for any call. A non-intrinsic call would have |
| 520 | + // already been detected when we looked for side effects, so this will |
| 521 | + // only notice intrinsic calls. |
| 522 | + useOperandNow = !FindAll<Call>(operand).list.empty(); |
| 523 | + } |
| 524 | + |
| 525 | + if (useOperandNow) { |
500 | 526 | use(operand); |
501 | 527 | } else { |
502 | 528 | // This data does not need to be read now, but might be read later. Note |
|
0 commit comments