aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/SelectOptimize.cpp
diff options
context:
space:
mode:
authorIgor Kirillov <igor.kirillov@arm.com>2024-12-10 16:29:20 +0000
committerGitHub <noreply@github.com>2024-12-10 16:29:20 +0000
commit444e53f675ff490a3023d48e1b809486513e3fd3 (patch)
treec0ef0fbe38a8accff4a8ca3cbc6f48ba27dff4d2 /llvm/lib/CodeGen/SelectOptimize.cpp
parent4f933277a53d61f7df42e70ec8ec465652019f7f (diff)
downloadllvm-444e53f675ff490a3023d48e1b809486513e3fd3.zip
llvm-444e53f675ff490a3023d48e1b809486513e3fd3.tar.gz
llvm-444e53f675ff490a3023d48e1b809486513e3fd3.tar.bz2
[SelectOpt] Fix incorrect IR for SUB when comparison dependent operand is first (#119362)
Diffstat (limited to 'llvm/lib/CodeGen/SelectOptimize.cpp')
-rw-r--r--llvm/lib/CodeGen/SelectOptimize.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/SelectOptimize.cpp b/llvm/lib/CodeGen/SelectOptimize.cpp
index 484705ea..2ec5af2d 100644
--- a/llvm/lib/CodeGen/SelectOptimize.cpp
+++ b/llvm/lib/CodeGen/SelectOptimize.cpp
@@ -806,7 +806,12 @@ void SelectOptimizeImpl::collectSelectGroups(BasicBlock &BB,
break;
}
- for (unsigned Idx = 0; Idx < 2; Idx++) {
+ // Iterate through operands and find dependant on recognised sign
+ // extending auxiliary select-like instructions. The operand index does
+ // not matter for Add and Or. However, for Sub, we can only safely
+ // transform when the operand is second.
+ unsigned Idx = BO->getOpcode() == Instruction::Sub ? 1 : 0;
+ for (; Idx < 2; Idx++) {
auto *Op = BO->getOperand(Idx);
auto It = SelectInfo.find(Op);
if (It != SelectInfo.end() && It->second.IsAuxiliary) {