From 51fc8153ce01ae7f4045a684ab2d73a4a69e5dcc Mon Sep 17 00:00:00 2001 From: Vladimir Radosavljevic Date: Wed, 20 Mar 2024 19:14:00 +0100 Subject: [PATCH] [EraVM] Fix xor optimization bug 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 --- llvm/lib/Target/EraVM/EraVMISelLowering.cpp | 2 ++ llvm/test/CodeGen/EraVM/xor-opt-bug.ll | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Target/EraVM/EraVMISelLowering.cpp b/llvm/lib/Target/EraVM/EraVMISelLowering.cpp index 823951121fa9..34e08f2e3e02 100644 --- a/llvm/lib/Target/EraVM/EraVMISelLowering.cpp +++ b/llvm/lib/Target/EraVM/EraVMISelLowering.cpp @@ -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); diff --git a/llvm/test/CodeGen/EraVM/xor-opt-bug.ll b/llvm/test/CodeGen/EraVM/xor-opt-bug.ll index cea4fa618330..5dd4a7e97b87 100644 --- a/llvm/test/CodeGen/EraVM/xor-opt-bug.ll +++ b/llvm/test/CodeGen/EraVM/xor-opt-bug.ll @@ -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