@@ -23,7 +23,7 @@ func.func @ObjectsMustDCE() {
2323 return
2424}
2525
26- om.class @StringConcatCanonicalization (%str1: !om.string , %str2: !om.string ) -> (out1 : !om.string , out2 : !om.string , out3 : !om.string , out4 : !om.string , out5 : !om.string , out6 : !om.string , out7 : !om.string ) {
26+ om.class @StringConcatCanonicalization (%str1: !om.string , %str2: !om.string ) -> (out1 : !om.string , out2 : !om.string , out3 : !om.string , out4 : !om.string , out5 : !om.string , out6 : !om.string , out7 : !om.string , out8 : !om.string ) {
2727 %s1 = om.constant " Hello" : !om.string
2828 %s2 = om.constant " World" : !om.string
2929 %s3 = om.constant " !" : !om.string
@@ -43,6 +43,9 @@ om.class @StringConcatCanonicalization(%str1: !om.string, %str2: !om.string) ->
4343 // Single operand replaced with operand
4444 %2 = om.string.concat %s1 : !om.string
4545
46+ // Single constant operand folds to the attribute.
47+ %singleConst = om.string.concat %s3 : !om.string
48+
4649 // Empty concat
4750 %3 = om.string.concat %empty , %empty : !om.string
4851
@@ -57,8 +60,40 @@ om.class @StringConcatCanonicalization(%str1: !om.string, %str2: !om.string) ->
5760 %nested = om.string.concat %str1 , %str2 : !om.string
5861 %concat1 = om.string.concat %nested , %s3 : !om.string
5962
60- // CHECK: om.class.fields [[HELLOWORLD]], [[HELLO]], [[HELLO]], [[EMPTY]], [[HELLOWORLD]], [[CONCAT1]], [[NESTED]]
61- om.class.fields %0 , %1 , %2 , %3 , %5 , %concat1 , %nested : !om.string , !om.string , !om.string , !om.string , !om.string , !om.string , !om.string
63+ // CHECK: om.class.fields [[HELLOWORLD]], [[HELLO]], [[HELLO]], [[CONST]], [[EMPTY]], [[HELLOWORLD]], [[CONCAT1]], [[NESTED]]
64+ om.class.fields %0 , %1 , %2 , %singleConst , %3 , %5 , %concat1 , %nested : !om.string , !om.string , !om.string , !om.string , !om.string , !om.string , !om.string , !om.string
65+ }
66+
67+ // CHECK-LABEL: @IntegerBinaryArithmeticFold
68+ om.class @IntegerBinaryArithmeticFold (%x: !om.integer ) -> (out1 : !om.integer , out2 : !om.integer ,
69+ out3 : !om.integer , out4 : !om.integer ,
70+ out5 : !om.integer , out6 : !om.integer ) {
71+ %i3 = om.constant #om.integer <3 : si4 > : !om.integer
72+ %i4 = om.constant #om.integer <4 : si4 > : !om.integer
73+ %i2 = om.constant #om.integer <2 : si4 > : !om.integer
74+ %neg1 = om.constant #om.integer <-1 : si4 > : !om.integer
75+ %i1 = om.constant #om.integer <1 : si4 > : !om.integer
76+ %wide = om.constant #om.integer <7 : si6 > : !om.integer
77+
78+ // CHECK-DAG: [[ADD:%.+]] = om.constant #om.integer<7 : si4> : !om.integer
79+ // CHECK-DAG: [[MUL:%.+]] = om.constant #om.integer<-4 : si4> : !om.integer
80+ // CHECK-DAG: [[SHR:%.+]] = om.constant #om.integer<1 : si4> : !om.integer
81+ // CHECK-DAG: [[SHL:%.+]] = om.constant #om.integer<-2 : si4> : !om.integer
82+ // CHECK-DAG: [[WIDEADD:%.+]] = om.constant #om.integer<9 : si6> : !om.integer
83+ // CHECK: [[DYN:%.+]] = om.integer.add %x, %{{.+}} : !om.integer
84+ %0 = om.integer.add %i3 , %i4 : !om.integer
85+ %1 = om.integer.mul %i3 , %i4 : !om.integer
86+ %2 = om.integer.shr %i4 , %i2 : !om.integer
87+ %3 = om.integer.shl %neg1 , %i1 : !om.integer
88+
89+ // Mixed bit widths should still fold after extending operands.
90+ %4 = om.integer.add %i2 , %wide : !om.integer
91+
92+ // Non-constant operands should remain.
93+ %5 = om.integer.add %x , %i1 : !om.integer
94+
95+ // CHECK: om.class.fields [[ADD]], [[MUL]], [[SHR]], [[SHL]], [[WIDEADD]], [[DYN]]
96+ om.class.fields %0 , %1 , %2 , %3 , %4 , %5 : !om.integer , !om.integer , !om.integer , !om.integer , !om.integer , !om.integer
6297}
6398
6499// CHECK-LABEL: @PropEqFold
0 commit comments