Auto merge of #136575 - scottmcm:nsuw-math, r=nikic
Set both `nuw` and `nsw` in slice size calculation There's an old note in the code to do this, and now that [LLVM-C has an API for it](f0b8ff1251/llvm/include/llvm-c/Core.h (L4403-L4408)
), we might as well. And it's been there since what looks like LLVM 17de9b6aa341
so doesn't even need to be conditional. (There's other places, like `RawVecInner` or `Layout`, that might want to do things like this too, but I'll leave those for a future PR.)
This commit is contained in:
commit
bdc97d1046
7 changed files with 81 additions and 44 deletions
|
@ -421,6 +421,37 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
|
|||
unchecked_umul(x, y) => LLVMBuildNUWMul,
|
||||
}
|
||||
|
||||
fn unchecked_suadd(&mut self, a: &'ll Value, b: &'ll Value) -> &'ll Value {
|
||||
unsafe {
|
||||
let add = llvm::LLVMBuildAdd(self.llbuilder, a, b, UNNAMED);
|
||||
if llvm::LLVMIsAInstruction(add).is_some() {
|
||||
llvm::LLVMSetNUW(add, True);
|
||||
llvm::LLVMSetNSW(add, True);
|
||||
}
|
||||
add
|
||||
}
|
||||
}
|
||||
fn unchecked_susub(&mut self, a: &'ll Value, b: &'ll Value) -> &'ll Value {
|
||||
unsafe {
|
||||
let sub = llvm::LLVMBuildSub(self.llbuilder, a, b, UNNAMED);
|
||||
if llvm::LLVMIsAInstruction(sub).is_some() {
|
||||
llvm::LLVMSetNUW(sub, True);
|
||||
llvm::LLVMSetNSW(sub, True);
|
||||
}
|
||||
sub
|
||||
}
|
||||
}
|
||||
fn unchecked_sumul(&mut self, a: &'ll Value, b: &'ll Value) -> &'ll Value {
|
||||
unsafe {
|
||||
let mul = llvm::LLVMBuildMul(self.llbuilder, a, b, UNNAMED);
|
||||
if llvm::LLVMIsAInstruction(mul).is_some() {
|
||||
llvm::LLVMSetNUW(mul, True);
|
||||
llvm::LLVMSetNSW(mul, True);
|
||||
}
|
||||
mul
|
||||
}
|
||||
}
|
||||
|
||||
fn or_disjoint(&mut self, a: &'ll Value, b: &'ll Value) -> &'ll Value {
|
||||
unsafe {
|
||||
let or = llvm::LLVMBuildOr(self.llbuilder, a, b, UNNAMED);
|
||||
|
|
|
@ -1430,6 +1430,8 @@ unsafe extern "C" {
|
|||
|
||||
// Extra flags on arithmetic
|
||||
pub(crate) fn LLVMSetIsDisjoint(Instr: &Value, IsDisjoint: Bool);
|
||||
pub(crate) fn LLVMSetNUW(ArithInst: &Value, HasNUW: Bool);
|
||||
pub(crate) fn LLVMSetNSW(ArithInst: &Value, HasNSW: Bool);
|
||||
|
||||
// Memory
|
||||
pub(crate) fn LLVMBuildAlloca<'a>(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue