@@ -169,11 +169,17 @@ define signext i32 @bset_i32_load(ptr %p, i32 signext %b) nounwind {
169
169
170
170
; We can use bsetw for 1 << x by setting the first source to zero.
171
171
define signext i32 @bset_i32_zero (i32 signext %a ) nounwind {
172
- ; CHECK-LABEL: bset_i32_zero:
173
- ; CHECK: # %bb.0:
174
- ; CHECK-NEXT: li a1, 1
175
- ; CHECK-NEXT: sllw a0, a1, a0
176
- ; CHECK-NEXT: ret
172
+ ; RV64I-LABEL: bset_i32_zero:
173
+ ; RV64I: # %bb.0:
174
+ ; RV64I-NEXT: li a1, 1
175
+ ; RV64I-NEXT: sllw a0, a1, a0
176
+ ; RV64I-NEXT: ret
177
+ ;
178
+ ; RV64ZBS-LABEL: bset_i32_zero:
179
+ ; RV64ZBS: # %bb.0:
180
+ ; RV64ZBS-NEXT: bset a0, zero, a0
181
+ ; RV64ZBS-NEXT: sext.w a0, a0
182
+ ; RV64ZBS-NEXT: ret
177
183
%shl = shl i32 1 , %a
178
184
ret i32 %shl
179
185
}
@@ -1076,3 +1082,78 @@ define i64 @or_i64_66901(i64 %a) nounwind {
1076
1082
%or = or i64 %a , 66901
1077
1083
ret i64 %or
1078
1084
}
1085
+
1086
+ define signext i32 @bset_trailing_ones_i32_mask (i32 signext %a ) nounwind {
1087
+ ; RV64I-LABEL: bset_trailing_ones_i32_mask:
1088
+ ; RV64I: # %bb.0:
1089
+ ; RV64I-NEXT: li a1, -1
1090
+ ; RV64I-NEXT: sllw a0, a1, a0
1091
+ ; RV64I-NEXT: not a0, a0
1092
+ ; RV64I-NEXT: ret
1093
+ ;
1094
+ ; RV64ZBS-LABEL: bset_trailing_ones_i32_mask:
1095
+ ; RV64ZBS: # %bb.0:
1096
+ ; RV64ZBS-NEXT: andi a0, a0, 31
1097
+ ; RV64ZBS-NEXT: bset a0, zero, a0
1098
+ ; RV64ZBS-NEXT: addiw a0, a0, -1
1099
+ ; RV64ZBS-NEXT: ret
1100
+ %and = and i32 %a , 31
1101
+ %shift = shl nsw i32 -1 , %and
1102
+ %not = xor i32 %shift , -1
1103
+ ret i32 %not
1104
+ }
1105
+
1106
+ define signext i32 @bset_trailing_ones_i32_no_mask (i32 signext %a ) nounwind {
1107
+ ; RV64I-LABEL: bset_trailing_ones_i32_no_mask:
1108
+ ; RV64I: # %bb.0:
1109
+ ; RV64I-NEXT: li a1, -1
1110
+ ; RV64I-NEXT: sllw a0, a1, a0
1111
+ ; RV64I-NEXT: not a0, a0
1112
+ ; RV64I-NEXT: ret
1113
+ ;
1114
+ ; RV64ZBS-LABEL: bset_trailing_ones_i32_no_mask:
1115
+ ; RV64ZBS: # %bb.0:
1116
+ ; RV64ZBS-NEXT: bset a0, zero, a0
1117
+ ; RV64ZBS-NEXT: addiw a0, a0, -1
1118
+ ; RV64ZBS-NEXT: ret
1119
+ %shift = shl nsw i32 -1 , %a
1120
+ %not = xor i32 %shift , -1
1121
+ ret i32 %not
1122
+ }
1123
+
1124
+ define signext i64 @bset_trailing_ones_i64_mask (i64 signext %a ) nounwind {
1125
+ ; RV64I-LABEL: bset_trailing_ones_i64_mask:
1126
+ ; RV64I: # %bb.0:
1127
+ ; RV64I-NEXT: li a1, -1
1128
+ ; RV64I-NEXT: sll a0, a1, a0
1129
+ ; RV64I-NEXT: not a0, a0
1130
+ ; RV64I-NEXT: ret
1131
+ ;
1132
+ ; RV64ZBS-LABEL: bset_trailing_ones_i64_mask:
1133
+ ; RV64ZBS: # %bb.0:
1134
+ ; RV64ZBS-NEXT: bset a0, zero, a0
1135
+ ; RV64ZBS-NEXT: addi a0, a0, -1
1136
+ ; RV64ZBS-NEXT: ret
1137
+ %and = and i64 %a , 63
1138
+ %shift = shl nsw i64 -1 , %and
1139
+ %not = xor i64 %shift , -1
1140
+ ret i64 %not
1141
+ }
1142
+
1143
+ define signext i64 @bset_trailing_ones_i64_no_mask (i64 signext %a ) nounwind {
1144
+ ; RV64I-LABEL: bset_trailing_ones_i64_no_mask:
1145
+ ; RV64I: # %bb.0:
1146
+ ; RV64I-NEXT: li a1, -1
1147
+ ; RV64I-NEXT: sll a0, a1, a0
1148
+ ; RV64I-NEXT: not a0, a0
1149
+ ; RV64I-NEXT: ret
1150
+ ;
1151
+ ; RV64ZBS-LABEL: bset_trailing_ones_i64_no_mask:
1152
+ ; RV64ZBS: # %bb.0:
1153
+ ; RV64ZBS-NEXT: bset a0, zero, a0
1154
+ ; RV64ZBS-NEXT: addi a0, a0, -1
1155
+ ; RV64ZBS-NEXT: ret
1156
+ %shift = shl nsw i64 -1 , %a
1157
+ %not = xor i64 %shift , -1
1158
+ ret i64 %not
1159
+ }
0 commit comments