Skip to content

Comparison of add of extended booleans not folded to xor #64859

Closed
@arsenm

Description

@arsenm

I was looking at some code that tried to compute a sort of enum scheme by adding booleans, and comparing to constant values which failed to form nice boolean code. This is really just an xor.

https://alive2.llvm.org/ce/z/RSnV-d

define i1 @src(i1 %arg, i1 %arg1) {
bb:
  %i = zext i1 %arg to i32
  %i2 = zext i1 %arg1 to i32
  %i3 = add nuw nsw i32 %i2, %i
  %i4 = icmp eq i32 %i3, 1
  ret i1 %i4
}

define i1 @tgt(i1 %arg, i1 %arg1) {
bb:
  %xor = xor i1 %arg, %arg1
  ret i1 %xor
}

Activity

elhewaty

elhewaty commented on Sep 4, 2023

@elhewaty
Member

Can I fix this? But I will need some help, as I am not familiar with LLVM system yet

elhewaty

elhewaty commented on Sep 4, 2023

@elhewaty
Member

%i4 = icmp eq i32 %i3, 1
what if the 1 were 0?

dc03

dc03 commented on Sep 4, 2023

@dc03
Member

%i4 = icmp eq i32 %i3, 1 what if the 1 were 0?

That would be equivalent to not(or(x, y)): https://alive2.llvm.org/ce/z/8z7Q4G

elhewaty

elhewaty commented on Sep 4, 2023

@elhewaty
Member

so the xor case holds for eq, 1, and zext only

dc03

dc03 commented on Sep 4, 2023

@dc03
Member

so the xor case holds for eq and 1 only

Yes, if you sketch out the truth table for this function you will see it is equivalent to the table for an xor, and with 0 it is equivalent to the table for a nor.

elhewaty

elhewaty commented on Sep 4, 2023

@elhewaty
Member

So we need to create a new function foldICmpAddExtI1 and handle all our cases? or do we have something like this already?

dc03

dc03 commented on Sep 4, 2023

@dc03
Member
elhewaty

elhewaty commented on Sep 6, 2023

@elhewaty
Member

@arsenm Here is a candidate patch : https://reviews.llvm.org/D159464

elhewaty

elhewaty commented on Sep 14, 2023

@elhewaty
Member

Can you please review the patch again.

elhewaty

elhewaty commented on Sep 20, 2023

@elhewaty
Member

@arsenm
ping

elhewaty

elhewaty commented on Sep 30, 2023

@elhewaty
Member

@arsenm @nikic @goldsteinn Here's a candidate pull: #67895

3 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @arsenm@elhewaty@dc03

    Issue actions

      Comparison of add of extended booleans not folded to xor · Issue #64859 · llvm/llvm-project