Skip to content

Commit

Permalink
[EraVM] Fix xor optimization bug
Browse files Browse the repository at this point in the history
This issue occurs when DAGCombiner in visitXOR incorrectly
folds !(x cc y) to (x !cc y) because isConstTrueVal returns
true for -1 constant. Fix this issue by setting that true
and false are represented with 1 and 0 values.

Signed-off-by: Vladimir Radosavljevic <[email protected]>
  • Loading branch information
vladimirradosavljevic committed Apr 2, 2024
1 parent 122a2f8 commit 51fc815
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions llvm/lib/Target/EraVM/EraVMISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ EraVMTargetLowering::EraVMTargetLowering(const TargetMachine &TM,
// Provide all sorts of operation actions
setStackPointerRegisterToSaveRestore(EraVM::SP);

setBooleanContents(ZeroOrOneBooleanContent);

// By default, expand all i256bit operations
for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc)
setOperationAction(Opc, MVT::i256, Expand);
Expand Down
4 changes: 3 additions & 1 deletion llvm/test/CodeGen/EraVM/xor-opt-bug.ll
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ define i256 @test(i256 %a) {
; CHECK: ; %bb.0:
; CHECK-NEXT: sub! r1, r0, r1
; CHECK-NEXT: add 0, r0, r1
; CHECK-NEXT: add.eq 1, r0, r1
; CHECK-NEXT: add.ne 1, r0, r1
; CHECK-NEXT: sub.s 1, r0, r2
; CHECK-NEXT: xor r1, r2, r1
; CHECK-NEXT: ret
%cmp = icmp ne i256 %a, 0
%zext = zext i1 %cmp to i256
Expand Down

0 comments on commit 51fc815

Please sign in to comment.