llvm.org GIT mirror llvm / 9af3d6f
[InstCombine] add commuted variants for power-of-2 checks; NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363945 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 30 days ago
1 changed file(s) with 47 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
104104 ret <2 x i1> %cmp
105105 }
106106
107 define i1 @is_pow2or0_negate_op_commute1(i32 %p) {
108 ; CHECK-LABEL: @is_pow2or0_negate_op_commute1(
109 ; CHECK-NEXT: [[X:%.*]] = srem i32 42, [[P:%.*]]
110 ; CHECK-NEXT: [[NEG:%.*]] = sub nsw i32 0, [[X]]
111 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X]], [[NEG]]
112 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], [[X]]
113 ; CHECK-NEXT: ret i1 [[CMP]]
114 ;
115 %x = srem i32 42, %p ; thwart complexity-based canonicalization
116 %neg = sub i32 0, %x
117 %and = and i32 %x, %neg
118 %cmp = icmp eq i32 %and, %x
119 ret i1 %cmp
120 }
121
122 ; x can't be <= complexity of the 'neg' but >= complexity of the 'and'.
123
124 define i1 @isnot_pow2or0_negate_op_commute2(i32 %p) {
125 ; CHECK-LABEL: @isnot_pow2or0_negate_op_commute2(
126 ; CHECK-NEXT: [[X:%.*]] = urem i32 42, [[P:%.*]]
127 ; CHECK-NEXT: [[NEG:%.*]] = sub nsw i32 0, [[X]]
128 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X]], [[NEG]]
129 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[X]], [[AND]]
130 ; CHECK-NEXT: ret i1 [[CMP]]
131 ;
132 %x = urem i32 42, %p ; thwart complexity-based canonicalization
133 %neg = sub i32 0, %x
134 %and = and i32 %neg, %x
135 %cmp = icmp ne i32 %x, %and
136 ret i1 %cmp
137 }
138
139 define i1 @isnot_pow2or0_negate_op_commute3(i32 %p) {
140 ; CHECK-LABEL: @isnot_pow2or0_negate_op_commute3(
141 ; CHECK-NEXT: [[X:%.*]] = urem i32 42, [[P:%.*]]
142 ; CHECK-NEXT: [[NEG:%.*]] = sub nsw i32 0, [[X]]
143 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X]], [[NEG]]
144 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[X]], [[AND]]
145 ; CHECK-NEXT: ret i1 [[CMP]]
146 ;
147 %x = urem i32 42, %p ; thwart complexity-based canonicalization
148 %neg = sub i32 0, %x
149 %and = and i32 %x, %neg
150 %cmp = icmp ne i32 %x, %and
151 ret i1 %cmp
152 }
153
107154 declare void @use(i32)
108155
109156 define i1 @is_pow2or0_negate_op_extra_use1(i32 %x) {