[PATCH] D125671: [InstCombine] Allow undef vectors when foldSelectToCopysign
Chenbing.Zheng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 16 01:32:43 PDT 2022
Chenbing.Zheng created this revision.
Chenbing.Zheng added reviewers: spatel, RKSimon, benshi001.
Chenbing.Zheng added a project: LLVM.
Herald added a subscriber: hiraditya.
Herald added a project: All.
Chenbing.Zheng requested review of this revision.
Herald added subscribers: llvm-commits, jacquesguan.
In function foldSelectToCopysign, we can allow undefs when
matching vectors.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D125671
Files:
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/select.ll
Index: llvm/test/Transforms/InstCombine/select.ll
===================================================================
--- llvm/test/Transforms/InstCombine/select.ll
+++ llvm/test/Transforms/InstCombine/select.ll
@@ -1689,13 +1689,10 @@
ret float %r
}
-; TODO: Allow undefs when matching vectors.
-
define <2 x float> @copysign4(<2 x float> %x) {
; CHECK-LABEL: @copysign4(
-; CHECK-NEXT: [[I:%.*]] = bitcast <2 x float> [[X:%.*]] to <2 x i32>
-; CHECK-NEXT: [[ISNEG:%.*]] = icmp slt <2 x i32> [[I]], zeroinitializer
-; CHECK-NEXT: [[R:%.*]] = select nnan arcp <2 x i1> [[ISNEG]], <2 x float> <float 4.200000e+01, float undef>, <2 x float> <float -4.200000e+01, float -4.200000e+01>
+; CHECK-NEXT: [[TMP1:%.*]] = fneg <2 x float> [[X:%.*]]
+; CHECK-NEXT: [[R:%.*]] = call <2 x float> @llvm.copysign.v2f32(<2 x float> <float 4.200000e+01, float undef>, <2 x float> [[TMP1]])
; CHECK-NEXT: ret <2 x float> [[R]]
;
%i = bitcast <2 x float> %x to <2 x i32>
Index: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -2277,7 +2277,8 @@
// Match select ?, TC, FC where the constants are equal but negated.
// TODO: Generalize to handle a negated variable operand?
const APFloat *TC, *FC;
- if (!match(TVal, m_APFloat(TC)) || !match(FVal, m_APFloat(FC)) ||
+ if (!match(TVal, m_APFloatAllowUndef(TC)) ||
+ !match(FVal, m_APFloatAllowUndef(FC)) ||
!abs(*TC).bitwiseIsEqual(abs(*FC)))
return nullptr;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125671.429642.patch
Type: text/x-patch
Size: 1641 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220516/572c5ac2/attachment.bin>
More information about the llvm-commits
mailing list