File: 2014-05-30-CombineAddNSW.ll

package info (click to toggle)
llvm-toolchain-3.7 1%3A3.7.1-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 345,556 kB
  • ctags: 362,199
  • sloc: cpp: 2,156,381; ansic: 458,339; objc: 91,547; python: 89,988; asm: 86,305; sh: 21,479; makefile: 6,853; perl: 5,601; ml: 5,458; pascal: 3,933; lisp: 2,429; xml: 686; cs: 239; php: 202; csh: 117
file content (20 lines) | stat: -rw-r--r-- 807 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
; RUN: llc < %s -march=x86-64 | FileCheck %s
; CHECK: addl

; The two additions are the same , but have different flags.
; In theory this code should never be generated by the frontend, but this 
; tries to test that two identical instructions with two different flags
; actually generate two different nodes.
;
; Normally the combiner would see this condition without the flags 
; and optimize the result of the sub into a register clear
; (the final result would be 0). With the different flags though the combiner 
; needs to keep the add + sub nodes, because the two nodes result as different
; nodes and so cannot assume that the subtraction of the two nodes
; generates 0 as result
define i32 @foo(i32 %a, i32 %b) {
  %1 = add i32 %a, %b
  %2 = add nsw i32 %a, %b
  %3 = sub i32 %1, %2
  ret i32 %3
}