@@ -992,6 +992,40 @@ ConstantRange llvm::getVScaleRange(const Function *F, unsigned BitWidth) {
992
992
return ConstantRange (Min, APInt (BitWidth, *AttrMax) + 1 );
993
993
}
994
994
995
+ void llvm::adjustKnownBitsForSelectArm (KnownBits &Known, Value *Cond,
996
+ Value *Arm, bool Invert, unsigned Depth,
997
+ const SimplifyQuery &Q) {
998
+ // If we have a constant arm, we are done.
999
+ if (Known.isConstant ())
1000
+ return ;
1001
+
1002
+ // See what condition implies about the bits of the select arm.
1003
+ KnownBits CondRes (Known.getBitWidth ());
1004
+ computeKnownBitsFromCond (Arm, Cond, CondRes, Depth + 1 , Q, Invert);
1005
+ // If we don't get any information from the condition, no reason to
1006
+ // proceed.
1007
+ if (CondRes.isUnknown ())
1008
+ return ;
1009
+
1010
+ // We can have conflict if the condition is dead. I.e if we have
1011
+ // (x | 64) < 32 ? (x | 64) : y
1012
+ // we will have conflict at bit 6 from the condition/the `or`.
1013
+ // In that case just return. Its not particularly important
1014
+ // what we do, as this select is going to be simplified soon.
1015
+ CondRes = CondRes.unionWith (Known);
1016
+ if (CondRes.hasConflict ())
1017
+ return ;
1018
+
1019
+ // Finally make sure the information we found is valid. This is relatively
1020
+ // expensive so it's left for the very end.
1021
+ if (!isGuaranteedNotToBeUndef (Arm, Q.AC , Q.CxtI , Q.DT , Depth + 1 ))
1022
+ return ;
1023
+
1024
+ // Finally, we know we get information from the condition and its valid,
1025
+ // so return it.
1026
+ Known = CondRes;
1027
+ }
1028
+
995
1029
static void computeKnownBitsFromOperator (const Operator *I,
996
1030
const APInt &DemandedElts,
997
1031
KnownBits &Known, unsigned Depth,
@@ -1048,36 +1082,8 @@ static void computeKnownBitsFromOperator(const Operator *I,
1048
1082
auto ComputeForArm = [&](Value *Arm, bool Invert) {
1049
1083
KnownBits Res (Known.getBitWidth ());
1050
1084
computeKnownBits (Arm, Res, Depth + 1 , Q);
1051
- // If we have a constant arm, we are done.
1052
- if (Res.isConstant ())
1053
- return Res;
1054
-
1055
- // See what condition implies about the bits of the two select arms.
1056
- KnownBits CondRes (Res.getBitWidth ());
1057
- computeKnownBitsFromCond (Arm, I->getOperand (0 ), CondRes, Depth + 1 , Q,
1058
- Invert);
1059
- // If we don't get any information from the condition, no reason to
1060
- // proceed.
1061
- if (CondRes.isUnknown ())
1062
- return Res;
1063
-
1064
- // We can have conflict if the condition is dead. I.e if we have
1065
- // (x | 64) < 32 ? (x | 64) : y
1066
- // we will have conflict at bit 6 from the condition/the `or`.
1067
- // In that case just return. Its not particularly important
1068
- // what we do, as this select is going to be simplified soon.
1069
- CondRes = CondRes.unionWith (Res);
1070
- if (CondRes.hasConflict ())
1071
- return Res;
1072
-
1073
- // Finally make sure the information we found is valid. This is relatively
1074
- // expensive so it's left for the very end.
1075
- if (!isGuaranteedNotToBeUndef (Arm, Q.AC , Q.CxtI , Q.DT , Depth + 1 ))
1076
- return Res;
1077
-
1078
- // Finally, we know we get information from the condition and its valid,
1079
- // so return it.
1080
- return CondRes;
1085
+ adjustKnownBitsForSelectArm (Res, I->getOperand (0 ), Arm, Invert, Depth, Q);
1086
+ return Res;
1081
1087
};
1082
1088
// Only known if known in both the LHS and RHS.
1083
1089
Known =
0 commit comments