1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00
llvm-mirror/test/Transforms/SCCP/overdefined-div.ll
Davide Italiano 65f612f852 [SCCP] Teach the pass how to handle div with overdefined operands.
This can prove that:

extern int f;
int g() {
    int x = 0;
    for (int i = 0; i < 365; ++i) {
        x /= f;
    }
    return x;
}

always returns zero. Thanks to Sanjoy for confirming this
transformation actually made sense (bugs are mine).

llvm-svn: 292531
2017-01-19 23:07:51 +00:00

33 lines
699 B
LLVM

; RUN: opt < %s -sccp -S | FileCheck %s
; Test that SCCP has basic knowledge of when div can nuke overdefined values.
; 0 / X = 0 even if X is overdefined.
; CHECK-LABEL: test1
; CHECK-NEXT: ret i32 0
define i32 @test1(i32 %foo) {
%tinkywinky = udiv i32 0, %foo
ret i32 %tinkywinky
}
; CHECK-LABEL: test2
; CHECK-NEXT: ret i32 0
define i32 @test2(i32 %foo) {
%tinkywinky = sdiv i32 0, %foo
ret i32 %tinkywinky
}
; CHECK-LABEL: test3
; CHECK: ret i32 %tinkywinky
define i32 @test3(i32 %foo) {
%tinkywinky = udiv i32 %foo, 0
ret i32 %tinkywinky
}
; CHECK-LABEL: test4
; CHECK: ret i32 %tinkywinky
define i32 @test4(i32 %foo) {
%tinkywinky = sdiv i32 %foo, 0
ret i32 %tinkywinky
}