[PATCH] D126174: [SelectionDAG] Fold abs(undef) to 0 instead of undef.
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun May 22 12:41:04 PDT 2022
craig.topper created this revision.
craig.topper added reviewers: efriedma, RKSimon, spatel.
Herald added subscribers: StephenFan, ecnelises, pengfei, hiraditya.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added a project: LLVM.
abs should only produce a positive value or the signed minimum
value. This means we can't fold abs(undef) to undef as that would
allow more values. Fold to 0 instead to match InstSimplify.
Fixes test mentioned in comment on pr55271.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D126174
Files:
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/test/CodeGen/X86/pr55271.ll
Index: llvm/test/CodeGen/X86/pr55271.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/pr55271.ll
@@ -0,0 +1,15 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
+
+; abs(undef) should fold to 0 not undef.
+
+declare i32 @llvm.abs.i32(i32, i1 immarg) #0
+
+define i32 @abs(i32 %0) {
+; CHECK-LABEL: abs:
+; CHECK: # %bb.0:
+; CHECK-NEXT: xorl %eax, %eax
+; CHECK-NEXT: retq
+ %2 = call i32 @llvm.abs.i32(i32 undef, i1 false)
+ ret i32 %2
+}
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -5243,7 +5243,7 @@
assert(VT.isInteger() && VT == Operand.getValueType() &&
"Invalid ABS!");
if (OpOpcode == ISD::UNDEF)
- return getUNDEF(VT);
+ return getConstant(0, DL, VT);
break;
case ISD::BSWAP:
assert(VT.isInteger() && VT == Operand.getValueType() &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126174.431248.patch
Type: text/x-patch
Size: 1144 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220522/1e63f864/attachment.bin>
More information about the llvm-commits
mailing list