[llvm-dev] Meaning of `sub nsw`
Cranmer, Joshua via llvm-dev
llvm-dev at lists.llvm.org
Fri Mar 1 06:49:30 PST 2019
In simple terms, nsw (for no signed wrap) means you invoke C-style undefined behavior should the operation have an overflow when interpreted as a signed operation.
-----Original Message-----
From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Peng Yu via llvm-dev
Sent: Friday, March 1, 2019 7:35
To: llvm-dev <llvm-dev at lists.llvm.org>
Subject: [llvm-dev] Meaning of `sub nsw`
In the following code.
unsigned char x1 = atoi(argv[1]);
unsigned char x2 = atoi(argv[2]);
printf("%d\n", x1-x2);
The substraction of the last command is translated to the following IR code.
%18 = load i8, i8* %6, align 1
%19 = zext i8 %18 to i32
%20 = load i8, i8* %7, align 1
%21 = zext i8 %20 to i32
%22 = sub nsw i32 %19, %21
I don't follow the explanation of nsw in langref. Could anybody help explain what nsw means here? Thanks.
--
Regards,
Peng
_______________________________________________
LLVM Developers mailing list
llvm-dev at lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
More information about the llvm-dev
mailing list