@@ -43,6 +43,23 @@ newtype TValueNumber =
43
43
} or
44
44
TUniqueValueNumber ( IRFunction irFunc , Instruction instr ) { uniqueValueNumber ( instr , irFunc ) }
45
45
46
+ /**
47
+ * A `ConvertInstruction` which converts data of type `T` to data of type `U`
48
+ * where `T` and `U` only differ in specifiers. For example, if `T` is `int`
49
+ * and `U` is `const T` this is a conversion from a non-const integer to a
50
+ * const integer.
51
+ *
52
+ * Generally, the value number of a converted value is different from the value
53
+ * number of an unconverted value, but conversions which only modify specifiers
54
+ * leave the resulting value bitwise identical to the old value.
55
+ */
56
+ class TypePreservingConvertInstruction extends ConvertInstruction {
57
+ TypePreservingConvertInstruction ( ) {
58
+ pragma [ only_bind_out ] ( this .getResultType ( ) .getUnspecifiedType ( ) ) =
59
+ pragma [ only_bind_out ] ( this .getUnary ( ) .getResultType ( ) .getUnspecifiedType ( ) )
60
+ }
61
+ }
62
+
46
63
/**
47
64
* A `CopyInstruction` whose source operand's value is congruent to the definition of that source
48
65
* operand.
@@ -216,6 +233,7 @@ private predicate unaryValueNumber(
216
233
not instr instanceof InheritanceConversionInstruction and
217
234
not instr instanceof CopyInstruction and
218
235
not instr instanceof FieldAddressInstruction and
236
+ not instr instanceof TypePreservingConvertInstruction and
219
237
instr .getOpcode ( ) = opcode and
220
238
tvalueNumber ( instr .getUnary ( ) ) = operand
221
239
}
@@ -351,6 +369,10 @@ private TValueNumber nonUniqueValueNumber(Instruction instr) {
351
369
or
352
370
// The value number of a copy is just the value number of its source value.
353
371
result = tvalueNumber ( instr .( CongruentCopyInstruction ) .getSourceValue ( ) )
372
+ or
373
+ // The value number of a type-preserving conversion is just the value
374
+ // number of the unconverted value.
375
+ result = tvalueNumber ( instr .( TypePreservingConvertInstruction ) .getUnary ( ) )
354
376
)
355
377
)
356
378
}
0 commit comments