Skip to content

trunc nuw x to i1 as branch/select cond implies x #96765

Closed
@sftlbcn

Description

@sftlbcn

https://alive2.llvm.org/ce/z/grTNkc

----------------------------------------
define i32 @src(i32 %x, i32 %y) {
#0:
  %trunc = trunc nuw i32 %x to i1
  %ret = select i1 %trunc, i32 %x, i32 %y
  ret i32 %ret
}
=>
define i32 @tgt(i32 %x, i32 %y) {
#0:
  %trunc = trunc nuw i32 %x to i1
  %ret = select i1 %trunc, i32 1, i32 %y
  ret i32 %ret
}
Transformation seems to be correct!


----------------------------------------
declare void @f()

define i32 @src2(i32 %x, i32 %y) {
bb1:
  %cond = trunc nuw i32 %x to i1
  br i1 %cond, label %bb2, label %bb3

bb2:
  call void @f()
  br label %bb3

bb3:
  %ret = phi i32 [ %y, %bb2 ], [ %x, %bb1 ]
  ret i32 %ret
}
=>
declare void @f()

define i32 @tgt2(i32 %x, i32 %y) {
bb1:
  %cond = trunc nuw i32 %x to i1
  br i1 %cond, label %bb2, label %bb3

bb2:
  call void @f()
  br label %bb3

bb3:
  %ret = phi i32 [ %y, %bb2 ], [ 0, %bb1 ]
  ret i32 %ret
}
Transformation seems to be correct!

Summary:
  2 correct transformations
  0 incorrect transformations
  0 failed-to-prove transformations
  0 Alive2 errors

Metadata

Metadata

Assignees

Labels

good first issuehttps://github.com/llvm/llvm-project/contributellvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passesmissed-optimization

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions