[llvm] 409ef45 - ValueTracking: Handle extractelement and extractvalue in computeKnownFPClass

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 14 11:37:04 PDT 2023


Author: Matt Arsenault
Date: 2023-04-14T14:36:56-04:00
New Revision: 409ef45000185d74b695a7dc94f5aeac0c4422d7

URL: https://github.com/llvm/llvm-project/commit/409ef45000185d74b695a7dc94f5aeac0c4422d7
DIFF: https://github.com/llvm/llvm-project/commit/409ef45000185d74b695a7dc94f5aeac0c4422d7.diff

LOG: ValueTracking: Handle extractelement and extractvalue in computeKnownFPClass

Added: 
    

Modified: 
    llvm/lib/Analysis/ValueTracking.cpp
    llvm/test/Transforms/Attributor/nofpclass.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 48a9dc1ac490..545ff49ba845 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4524,6 +4524,29 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
 
     break;
   }
+  case Instruction::ExtractElement: {
+    // Look through extract element. If the index is non-constant or
+    // out-of-range demand all elements, otherwise just the extracted element.
+    const Value *Vec = Op->getOperand(0);
+    const Value *Idx = Op->getOperand(1);
+    auto *CIdx = dyn_cast<ConstantInt>(Idx);
+
+    if (auto *VecTy = dyn_cast<FixedVectorType>(Vec->getType())) {
+      unsigned NumElts = VecTy->getNumElements();
+      APInt DemandedVecElts = APInt::getAllOnes(NumElts);
+      if (CIdx && CIdx->getValue().ult(NumElts))
+        DemandedVecElts = APInt::getOneBitSet(NumElts, CIdx->getZExtValue());
+      return computeKnownFPClass(Vec, DemandedVecElts, InterestedClasses, Known,
+                                 Depth + 1, Q, TLI);
+    }
+
+    break;
+  }
+  case Instruction::ExtractValue: {
+    computeKnownFPClass(Op->getOperand(0), DemandedElts, InterestedClasses,
+                        Known, Depth + 1, Q, TLI);
+    break;
+  }
   default:
     break;
   }

diff  --git a/llvm/test/Transforms/Attributor/nofpclass.ll b/llvm/test/Transforms/Attributor/nofpclass.ll
index 302abebd8ff6..a363933fcfe9 100644
--- a/llvm/test/Transforms/Attributor/nofpclass.ll
+++ b/llvm/test/Transforms/Attributor/nofpclass.ll
@@ -829,3 +829,58 @@ entry:
   call void @extern.use(float %arg)
   ret float %arg
 }
+
+define float @returned_extractelement_dynamic_index(<4 x float> nofpclass(nan) %vec, i32 %idx) {
+; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
+; CHECK-LABEL: define nofpclass(nan) float @returned_extractelement_dynamic_index
+; CHECK-SAME: (<4 x float> nofpclass(nan) [[VEC:%.*]], i32 [[IDX:%.*]]) #[[ATTR2]] {
+; CHECK-NEXT:    [[EXTRACT:%.*]] = extractelement <4 x float> [[VEC]], i32 [[IDX]]
+; CHECK-NEXT:    ret float [[EXTRACT]]
+;
+  %extract = extractelement <4 x float> %vec, i32 %idx
+  ret float %extract
+}
+
+define float @returned_extractelement_index0(<4 x float> nofpclass(nan) %vec) {
+; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
+; CHECK-LABEL: define nofpclass(nan) float @returned_extractelement_index0
+; CHECK-SAME: (<4 x float> nofpclass(nan) [[VEC:%.*]]) #[[ATTR2]] {
+; CHECK-NEXT:    [[EXTRACT:%.*]] = extractelement <4 x float> [[VEC]], i32 0
+; CHECK-NEXT:    ret float [[EXTRACT]]
+;
+  %extract = extractelement <4 x float> %vec, i32 0
+  ret float %extract
+}
+
+define float @returned_extractelement_index_oob(<4 x float> nofpclass(nan) %vec) {
+; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
+; CHECK-LABEL: define nofpclass(nan) float @returned_extractelement_index_oob
+; CHECK-SAME: (<4 x float> nofpclass(nan) [[VEC:%.*]]) #[[ATTR2]] {
+; CHECK-NEXT:    [[EXTRACT:%.*]] = extractelement <4 x float> [[VEC]], i32 5
+; CHECK-NEXT:    ret float [[EXTRACT]]
+;
+  %extract = extractelement <4 x float> %vec, i32 5
+  ret float %extract
+}
+
+define float @returned_extractelement_scalable(<vscale x 4 x float> nofpclass(nan) %vec) {
+; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
+; CHECK-LABEL: define float @returned_extractelement_scalable
+; CHECK-SAME: (<vscale x 4 x float> nofpclass(nan) [[VEC:%.*]]) #[[ATTR2]] {
+; CHECK-NEXT:    [[EXTRACT:%.*]] = extractelement <vscale x 4 x float> [[VEC]], i32 0
+; CHECK-NEXT:    ret float [[EXTRACT]]
+;
+  %extract = extractelement <vscale x 4 x float> %vec, i32 0
+  ret float %extract
+}
+
+define float @returned_extractvalue([4 x float] nofpclass(nan) %array) {
+; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
+; CHECK-LABEL: define nofpclass(nan) float @returned_extractvalue
+; CHECK-SAME: ([4 x float] nofpclass(nan) [[ARRAY:%.*]]) #[[ATTR2]] {
+; CHECK-NEXT:    [[EXTRACT:%.*]] = extractvalue [4 x float] [[ARRAY]], 0
+; CHECK-NEXT:    ret float [[EXTRACT]]
+;
+  %extract = extractvalue [4 x float] %array, 0
+  ret float %extract
+}


        


More information about the llvm-commits mailing list