Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FastISel][AArch64] Compare Instruction Miscompilation Fix #75993

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions llvm/lib/Target/AArch64/AArch64FastISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1231,15 +1231,6 @@ unsigned AArch64FastISel::emitAddSub(bool UseAdd, MVT RetVT, const Value *LHS,
// Only extend the RHS within the instruction if there is a valid extend type.
if (ExtendType != AArch64_AM::InvalidShiftExtend && RHS->hasOneUse() &&
isValueAvailable(RHS)) {
if (const auto *SI = dyn_cast<BinaryOperator>(RHS))
if (const auto *C = dyn_cast<ConstantInt>(SI->getOperand(1)))
if ((SI->getOpcode() == Instruction::Shl) && (C->getZExtValue() < 4)) {
Register RHSReg = getRegForValue(SI->getOperand(0));
if (!RHSReg)
return 0;
return emitAddSub_rx(UseAdd, RetVT, LHSReg, RHSReg, ExtendType,
C->getZExtValue(), SetFlags, WantResult);
}
Register RHSReg = getRegForValue(RHS);
if (!RHSReg)
return 0;
Expand Down Expand Up @@ -2426,7 +2417,7 @@ bool AArch64FastISel::selectBranch(const Instruction *I) {
}

// Emit the cmp.
if (!emitCmp(CI->getOperand(0), CI->getOperand(1), CI->isUnsigned()))
if (!emitCmp(CI->getOperand(0), CI->getOperand(1), !CI->isSigned()))
return false;

// FCMP_UEQ and FCMP_ONE cannot be checked with a single branch
Expand Down
15 changes: 15 additions & 0 deletions llvm/test/CodeGen/AArch64/fastisel-shift-and-cmp.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; RUN: llc -fast-isel -mtriple=aarch64-none-none < %s | FileCheck %s

; Check that the shl instruction did not get folded in together with
; the cmp instruction. It would create a miscompilation

define i32 @icmp_i8_shift_and_cmp(i8 %a, i8 %b) {
%op1 = xor i8 %a, -49
%op2 = mul i8 %op1, %op1
; CHECK-NOT: cmp [[REGS:.*]] #[[SHIFT_VAL:[0-9]+]]
%op3 = shl i8 %op2, 3
%tmp3 = icmp eq i8 %b, %op3
%conv = zext i1 %tmp3 to i32
ret i32 %conv
}