Skip to content

Commit c715c88

Browse files
committed
bug reproducer
Signed-off-by: Andy Sadler <[email protected]>
1 parent 3d97550 commit c715c88

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

src/intrinsic/mod.rs

+7-19
Original file line numberDiff line numberDiff line change
@@ -819,19 +819,6 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
819819
value
820820
};
821821

822-
// only break apart 128-bit ints if they're not natively supported
823-
// TODO(antoyo): remove this if/when native 128-bit integers land in libgccjit
824-
if value_type.is_u128(&self.cx) && !self.cx.supports_128bit_integers {
825-
let sixty_four = self.gcc_int(value_type, 64);
826-
let right_shift = self.gcc_lshr(value, sixty_four);
827-
let high = self.gcc_int_cast(right_shift, self.cx.ulonglong_type);
828-
let high = self.pop_count(high);
829-
let low = self.gcc_int_cast(value, self.cx.ulonglong_type);
830-
let low = self.pop_count(low);
831-
let res = high + low;
832-
return self.gcc_int_cast(res, result_type);
833-
}
834-
835822
// Use Wenger's algorithm for population count, gcc's seems to play better with it
836823
// for (int counter = 0; value != 0; counter++) {
837824
// value &= value - 1;
@@ -844,30 +831,31 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
844831
let counter_type = self.int_type;
845832
let counter = self.current_func().new_local(None, counter_type, "popcount_counter");
846833
let val = self.current_func().new_local(None, value_type, "popcount_value");
847-
let zero = self.context.new_rvalue_zero(counter_type);
834+
let zero = self.gcc_zero(counter_type);
848835
self.llbb().add_assignment(None, counter, zero);
849836
self.llbb().add_assignment(None, val, value);
850837
self.br(loop_head);
851838

852839
// check if value isn't zero
853840
self.switch_to_block(loop_head);
854-
let zero = self.context.new_rvalue_zero(value_type);
855-
let cond = self.context.new_comparison(None, ComparisonOp::NotEquals, val.to_rvalue(), zero);
841+
let zero = self.gcc_zero(value_type);
842+
let cond = self.gcc_icmp(IntPredicate::IntNE, val.to_rvalue(), zero);
856843
self.cond_br(cond, loop_body, loop_tail);
857844

858845
// val &= val - 1;
859846
self.switch_to_block(loop_body);
860-
let sub = val.to_rvalue() - self.context.new_rvalue_one(value_type);
847+
let one = self.gcc_int(value_type, 1);
848+
let sub = self.gcc_sub(val.to_rvalue(), one);
861849
loop_body.add_assignment_op(None, val, BinaryOp::BitwiseAnd, sub);
862850

863851
// counter += 1
864-
let one = self.context.new_rvalue_one(counter_type);
852+
let one = self.gcc_int(counter_type, 1);
865853
loop_body.add_assignment_op(None, counter, BinaryOp::Plus, one);
866854
self.br(loop_head);
867855

868856
// end of loop
869857
self.switch_to_block(loop_tail);
870-
self.context.new_cast(None, counter.to_rvalue(), result_type)
858+
self.gcc_int_cast(counter.to_rvalue(), result_type)
871859
}
872860

873861
// Algorithm from: https://blog.regehr.org/archives/1063

src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ impl LockedTargetInfo {
149149
}
150150

151151
fn supports_128bit_int(&self) -> bool {
152-
self.info.lock().expect("lock").supports_128bit_int()
152+
// self.info.lock().expect("lock").supports_128bit_int()
153+
false
153154
}
154155
}
155156

0 commit comments

Comments
 (0)