From 0d5276cc593293442edebd52c4040619e9daf7ba Mon Sep 17 00:00:00 2001 From: Bart Coppens Date: Tue, 16 Jan 2024 18:47:57 +0100 Subject: [PATCH] Generating an invert operation for boolean xor is invalid in most contexts due to integer promotion (#192) --- lib/Target/CBackend/CBackend.cpp | 4 ---- test/ll_tests/test_if_bool_xor.ll | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 test/ll_tests/test_if_bool_xor.ll diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index a1b0620b..09ffb0ca 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -4215,10 +4215,6 @@ void CWriter::visitBinaryOperator(BinaryOperator &I) { Out << "-("; writeOperand(X); Out << ")"; - } else if (match(&I, m_Not(m_Value(X)))) { - Out << "~("; - writeOperand(X); - Out << ")"; } else if (I.getOpcode() == Instruction::FRem) { // Output a call to fmod/fmodf instead of emitting a%b if (I.getType() == Type::getFloatTy(I.getContext())) diff --git a/test/ll_tests/test_if_bool_xor.ll b/test/ll_tests/test_if_bool_xor.ll new file mode 100644 index 00000000..fa8cf888 --- /dev/null +++ b/test/ll_tests/test_if_bool_xor.ll @@ -0,0 +1,15 @@ +define dso_local i1 @a() { + ret i1 1 +} + +define dso_local i32 @main() #0 { + %ret = call zeroext i1 @a() + %cond = xor i1 %ret, true + br i1 %cond, label %a_is_false, label %a_is_true + +a_is_false: + ret i32 -1 + +a_is_true: + ret i32 6 +}