Commit 26ccc6b
[InstCombine] Drop nuw flag when CtlzOp is a sub nuw (#91776)
See the following case:
```
define i32 @SRC1(i32 %x) {
%dec = sub nuw i32 -2, %x
%ctlz = tail call i32 @llvm.ctlz.i32(i32 %dec, i1 false)
%sub = sub nsw i32 32, %ctlz
%shl = shl i32 1, %sub
%ugt = icmp ult i32 %x, -2
%sel = select i1 %ugt, i32 %shl, i32 1
ret i32 %sel
}
define i32 @tgt1(i32 %x) {
%dec = sub nuw i32 -2, %x
%ctlz = tail call i32 @llvm.ctlz.i32(i32 %dec, i1 false)
%sub = sub nsw i32 32, %ctlz
%and = and i32 %sub, 31
%shl = shl nuw i32 1, %and
ret i32 %shl
}
```
`nuw` in `%dec` should be dropped after the select instruction is
eliminated.
Alive2: https://alive2.llvm.org/ce/z/7S9529
Fixes #91691.
(cherry picked from commit b5f4210)1 parent aa2549e commit 26ccc6b
File tree
2 files changed
+48
-2
lines changed- llvm
- lib/Transforms/InstCombine
- test/Transforms/InstCombine
2 files changed
+48
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3201 | 3201 | | |
3202 | 3202 | | |
3203 | 3203 | | |
3204 | | - | |
| 3204 | + | |
| 3205 | + | |
3205 | 3206 | | |
3206 | 3207 | | |
3207 | 3208 | | |
| |||
3224 | 3225 | | |
3225 | 3226 | | |
3226 | 3227 | | |
| 3228 | + | |
| 3229 | + | |
3227 | 3230 | | |
3228 | 3231 | | |
3229 | 3232 | | |
| |||
3237 | 3240 | | |
3238 | 3241 | | |
3239 | 3242 | | |
| 3243 | + | |
3240 | 3244 | | |
3241 | 3245 | | |
3242 | 3246 | | |
| |||
3306 | 3310 | | |
3307 | 3311 | | |
3308 | 3312 | | |
| 3313 | + | |
| 3314 | + | |
3309 | 3315 | | |
3310 | 3316 | | |
3311 | 3317 | | |
3312 | 3318 | | |
3313 | 3319 | | |
3314 | | - | |
| 3320 | + | |
| 3321 | + | |
3315 | 3322 | | |
3316 | 3323 | | |
| 3324 | + | |
| 3325 | + | |
| 3326 | + | |
3317 | 3327 | | |
3318 | 3328 | | |
3319 | 3329 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
287 | 323 | | |
288 | 324 | | |
289 | 325 | | |
0 commit comments