[PATCH] Added InstCombine transformation for combining two instructions icmp ult/ule/uge/ugt (ashr/lshr (Const2) %A), (Const1)

Ankur Garg ankur29.garg at samsung.com
Mon Nov 10 21:14:30 PST 2014


Here is the ALIVe input I used to test the optimization:


```
Name: 1
Pre: C1 == C2 && C1 < 0 && C2 != -1
 %shr = ashr i8 C2, %a
 %cmp = icmp ule i8 %shr, C1
=>
 %cmp = icmp eq i8 %a, 0

Name: 2
Pre: C1 == C2 && C1 < 0 && C2 != -1
 %shr = ashr i8 C2, %a
 %cmp = icmp ugt i8 %shr, C1
=>
 %cmp = icmp ne i8 %a, 0

Name: 3
Pre: C1 == C2 && C1 < 0 && C2 != -1
 %shr = ashr i8 C2, %a
 %cmp = icmp ult i8 %shr, C1
=>
 %cmp = i1 false

Name: 4
Pre: C1 == C2 && C1 < 0 && C2 != -1
 %shr = ashr i8 C2, %a
 %cmp = icmp uge i8 %shr, C1
=>
 %cmp = i1 true
 
Name: 5
Pre: C1 == C2 && C2 != -1 && C2 != 0
 %shr = lshr i8 C2, %a
 %cmp = icmp ult i8 %shr, C1
=>
 %cmp = icmp ugt i8 %a, 0

Name: 6
Pre: C1 == C2 && C2 != -1 && C2 != 0
 %shr = lshr i8 C2, %a
 %cmp = icmp uge i8 %shr, C1
=>
 %cmp = icmp eq i8 %a, 0

Name: 7
Pre: C1 == C2 && C2 != -1 && C2 != 0
 %shr = lshr i8 C2, %a
 %cmp = icmp ule i8 %shr, C1
=>
 %cmp = i1 true

Name: 8
Pre: C1 == C2 && C2 != -1 && C2 != 0
 %shr = lshr i8 C2, %a
 %cmp = icmp ugt i8 %shr, C1
=>
 %cmp = i1 false

Name: 9
Pre: C1 == C2 && C1 > 0
 %shr = ashr i8 C2, %a
 %cmp = icmp ult i8 %shr, C1
=>
 %cmp = icmp ugt i8 %a, 0

Name: 10
Pre: C1 == C2 && C1 > 0
 %shr = ashr i8 C2, %a
 %cmp = icmp ule i8 %shr, C1
=>
 %cmp = i1 true

Name: 11
Pre: C1 == C2 && C1 > 0
 %shr = ashr i8 C2, %a
 %cmp = icmp ugt i8 %shr, C1
=>
 %cmp = i1 false

Name: 12
Pre: C1 == C2 && C1 > 0
 %shr = ashr i8 C2, %a
 %cmp = icmp uge i8 %shr, C1
=>
 %cmp = icmp eq i8 %a, 0

Name: 13
Pre: C1 != C2 && C1 < 0 && C2 < C1 && C2 >> (log2(~C2) - log2(~C1)) == C1
 %shr = ashr i8 C2, %a
 %cmp = icmp uge i8 %shr, C1
=>
 %cmp = icmp uge i8 %a, log2(~C2) - log2(~C1)

Name: 14
Pre: C1 != C2 && C1 < 0 && C2 < C1 && C2 >> (log2(~C2) - log2(~C1)) == C1
 %shr = ashr i8 C2, %a
 %cmp = icmp ugt i8 %shr, C1
=>
 %cmp = icmp ugt i8 %a, log2(~C2) - log2(~C1)
 
Name: 15
Pre: C1 != C2 && C1 < 0 && C2 < C1 && C2 >> (log2(~C2) - log2(~C1)) == C1
 %shr = ashr i8 C2, %a
 %cmp = icmp ule i8 %shr, C1
=>
 %cmp = icmp ule i8 %a, log2(~C2) - log2(~C1)

Name: 16
Pre: C1 != C2 && C1 < 0 && C2 < C1 && C2 >> (log2(~C2) - log2(~C1)) == C1
 %shr = ashr i8 C2, %a
 %cmp = icmp ult i8 %shr, C1
=>
 %cmp = icmp ult i8 %a, log2(~C2) - log2(~C1)


Name: 17
Pre: C1 != C2 && C1 < 0 && C2 < C1 && (C2 >> (log2(~C2) - log2(~C1))) u> (C1)
 %shr = ashr i8 C2, %a
 %cmp = icmp uge i8 %shr, C1
=>
 %cmp = icmp ugt i8 %a, log2(~C2) - log2(~C1) - 1

Name: 18
Pre: C1 != C2 && C1 < 0 && C2 < C1 && (C2 >> (log2(~C2) - log2(~C1))) u> (C1)
 %shr = ashr i8 C2, %a
 %cmp = icmp ugt i8 %shr, C1
=>
 %cmp = icmp ugt i8 %a, log2(~C2) - log2(~C1) - 1

Name: 19
Pre: C1 != C2 && C1 < 0 && C2 < C1 && (C2 >> (log2(~C2) - log2(~C1))) u> (C1)
 %shr = ashr i8 C2, %a
 %cmp = icmp ult i8 %shr, C1
=>
 %cmp = icmp ult i8 %a, log2(~C2) - log2(~C1)

Name: 20
Pre: C1 != C2 && C1 < 0 && C2 < C1 && (C2 >> (log2(~C2) - log2(~C1))) u> (C1)
 %shr = ashr i8 C2, %a
 %cmp = icmp ule i8 %shr, C1
=>
 %cmp = icmp ult i8 %a, log2(~C2) - log2(~C1)

Name: 21
Pre: C1 != C2 && C1 < -1 && C2 < C1 && (C2 >> (log2(~C2) - log2(~C1))) u< (C1)
 %shr = ashr i8 C2, %a
 %cmp = icmp uge i8 %shr, C1
=>
 %cmp = icmp ugt i8 %a, log2(~C2) - log2(~C1)

Name: 22
Pre: C1 != C2 && C1 < -1 && C2 < C1 && (C2 >> (log2(~C2) - log2(~C1))) u< (C1)
 %shr = ashr i8 C2, %a
 %cmp = icmp ugt i8 %shr, C1
=>
 %cmp = icmp ugt i8 %a, log2(~C2) - log2(~C1)

Name: 23
Pre: C1 != C2 && C1 < -1 && C2 < C1 && (C2 >> (log2(~C2) - log2(~C1))) u< (C1)
 %shr = ashr i8 C2, %a
 %cmp = icmp ult i8 %shr, C1
=>
 %cmp = icmp ult i8 %a, log2(~C2) - log2(~C1) + 1

Name: 24
Pre: C1 != C2 && C1 < -1 && C2 < C1 && (C2 >> (log2(~C2) - log2(~C1))) u< (C1)
 %shr = ashr i8 C2, %a
 %cmp = icmp ule i8 %shr, C1
=>
 %cmp = icmp ult i8 %a, log2(~C2) - log2(~C1) + 1
 
Name: 25
Pre: C1 != C2 && C1 > 0 && C1 u> C2
 %shr = ashr i8 C2, %a
 %cmp = icmp uge i8 %shr, C1
=>
 %cmp = i1 false

Name: 26
Pre: C1 != C2 && C1 > 0 && C1 u> C2
 %shr = ashr i8 C2, %a
 %cmp = icmp ugt i8 %shr, C1
=>
 %cmp = i1 false

Name: 27
Pre: C1 != C2 && C1 > 0 && C1 u> C2
 %shr = ashr i8 C2, %a
 %cmp = icmp ule i8 %shr, C1
=>
 %cmp = i1 true

Name: 28
Pre: C1 != C2 && C1 > 0 && C1 u> C2
 %shr = ashr i8 C2, %a
 %cmp = icmp ult i8 %shr, C1
=>
 %cmp = i1 true

Name: 29
Pre: C1 != C2 && C1 > 0 && C2 > 0 && (C1 u< C2) && C1 == lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = ashr i8 C2, %a
 %cmp = icmp ult i8 %shr, C1
=>
 %cmp = icmp ugt i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2)

Name: 30
Pre: C1 != C2 && C1 > 0 && C2 > 0 && (C1 u< C2) && C1 == lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = ashr i8 C2, %a
 %cmp = icmp ule i8 %shr, C1
=>
 %cmp = icmp uge i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2)

Name: 31
Pre: C1 != C2 && C1 > 0 && C2 > 0 && (C1 u< C2) && C1 == lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = ashr i8 C2, %a
 %cmp = icmp ugt i8 %shr, C1
=>
 %cmp = icmp ult i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2)

Name: 32
Pre: C1 != C2 && C1 > 0 && C2 > 0 && (C1 u< C2) && C1 == lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = ashr i8 C2, %a
 %cmp = icmp uge i8 %shr, C1
=>
 %cmp = icmp ule i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2)
 
Name: 33
Pre: C1 != C2 && C1 > 0 && C2 > 0 && C1 u< C2 && C1 u> lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = ashr i8 C2, %a
 %cmp = icmp ult i8 %shr, C1
=>
 %cmp = icmp ugt i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2) - 1

Name: 34
Pre: C1 != C2 && C1 > 0 && C2 > 0 && C1 u< C2 && C1 u> lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = ashr i8 C2, %a
 %cmp = icmp ule i8 %shr, C1
=>
 %cmp = icmp ugt i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2) - 1

Name: 35
Pre: C1 != C2 && C1 > 0 && C2 > 0 && C1 u< C2 && C1 u> lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = ashr i8 C2, %a
 %cmp = icmp ugt i8 %shr, C1
=>
 %cmp = icmp ule i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2) - 1

Name: 36
Pre: C1 != C2 && C1 > 0 && C2 > 0 && C1 u< C2 && C1 u> lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = ashr i8 C2, %a
 %cmp = icmp uge i8 %shr, C1
=>
 %cmp = icmp ule i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2) - 1


Name: 37
Pre: C1 != C2 && C1 > 0 && C2 > 0 && C1 u< C2 && C1 u< lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = ashr i8 C2, %a
 %cmp = icmp ult i8 %shr, C1
=>
 %cmp = icmp ugt i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2)

Name: 38
Pre: C1 != C2 && C1 > 0 && C2 > 0 && C1 u< C2 && C1 u< lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = ashr i8 C2, %a
 %cmp = icmp ule i8 %shr, C1
=>
 %cmp = icmp ugt i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2)

Name: 39
Pre: C1 != C2 && C1 > 0 && C2 > 0 && C1 u< C2 && C1 u< lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = ashr i8 C2, %a
 %cmp = icmp ugt i8 %shr, C1
=>
 %cmp = icmp ule i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2)

Name: 40
Pre: C1 != C2 && C1 > 0 && C2 > 0 && C1 u< C2 && C1 u< lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = ashr i8 C2, %a
 %cmp = icmp uge i8 %shr, C1
=>
 %cmp = icmp ule i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2)
 
Name: 41
Pre: C1 != C2 && C1 u> C2
 %shr = lshr i8 C2, %a
 %cmp = icmp uge i8 %shr, C1
=>
 %cmp = i1 false

Name: 42
Pre: C1 != C2 && C1 u> C2
 %shr = lshr i8 C2, %a
 %cmp = icmp ugt i8 %shr, C1
=>
 %cmp = i1 false

Name: 43
Pre: C1 != C2 && C1 u> C2
 %shr = lshr i8 C2, %a
 %cmp = icmp ule i8 %shr, C1
=>
 %cmp = i1 true

Name: 44
Pre: C1 != C2 && C1 u> C2
 %shr = lshr i8 C2, %a
 %cmp = icmp ult i8 %shr, C1
=>
 %cmp = i1 true

Name: 45
Pre: C1 != 0 && C2 != 0 && C1 != C2 && C1 u< C2 && C1 == lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = lshr i8 C2, %a
 %cmp = icmp ult i8 %shr, C1
=>
 %cmp = icmp ugt i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2)

Name: 46
Pre: C1 != 0 && C2 != 0 && C1 != C2 && C1 u< C2 && C1 == lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = lshr i8 C2, %a
 %cmp = icmp ule i8 %shr, C1
=>
 %cmp = icmp uge i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2)

Name: 47
Pre: C1 != 0 && C2 != 0 && C1 != C2 && C1 u< C2 && C1 == lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = lshr i8 C2, %a
 %cmp = icmp ugt i8 %shr, C1
=>
 %cmp = icmp ult i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2)

Name: 48
Pre: C1 != 0 && C2 != 0 && C1 != C2 && C1 u< C2 && C1 == lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = lshr i8 C2, %a
 %cmp = icmp uge i8 %shr, C1
=>
 %cmp = icmp ule i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2)
 
Name: 49
Pre: C1 != 0 && C2 != 0 && C1 != C2 && C1 u< C2 && C1 u> lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = lshr i8 C2, %a
 %cmp = icmp ult i8 %shr, C1
=>
 %cmp = icmp ugt i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2) - 1

Name: 50
Pre: C1 != 0 && C2 != 0 && C1 != C2 && C1 u< C2 && C1 u> lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = lshr i8 C2, %a
 %cmp = icmp ule i8 %shr, C1
=>
 %cmp = icmp ugt i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2) - 1

Name: 51
Pre: C1 != 0 && C2 != 0 && C1 != C2 && C1 u< C2 && C1 u> lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = lshr i8 C2, %a
 %cmp = icmp ugt i8 %shr, C1
=>
 %cmp = icmp ule i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2) - 1

Name: 52
Pre: C1 != 0 && C2 != 0 && C1 != C2 && C1 u< C2 && C1 u> lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = lshr i8 C2, %a
 %cmp = icmp uge i8 %shr, C1
=>
 %cmp = icmp ule i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2) - 1

Name: 53
Pre: C1 != 0 && C2 != 0 && C1 != C2 && C1 u< C2 && C1 u< lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = lshr i8 C2, %a
 %cmp = icmp ult i8 %shr, C1
=>
 %cmp = icmp ugt i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2)

Name: 54
Pre: C1 != 0 && C2 != 0 && C1 != C2 && C1 u< C2 && C1 u< lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = lshr i8 C2, %a
 %cmp = icmp ule i8 %shr, C1
=>
 %cmp = icmp ugt i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2)

Name: 55
Pre: C1 != 0 && C2 != 0 && C1 != C2 && C1 u< C2 && C1 u< lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = lshr i8 C2, %a
 %cmp = icmp ugt i8 %shr, C1
=>
 %cmp = icmp ule i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2)

Name: 56
Pre: C1 != 0 && C2 != 0 && C1 != C2 && C1 u< C2 && C1 u< lshr(C2, countLeadingZeros(C1) - countLeadingZeros(C2))
 %shr = lshr i8 C2, %a
 %cmp = icmp uge i8 %shr, C1
=>
 %cmp = icmp ule i8 %a, countLeadingZeros(C1) - countLeadingZeros(C2)
```

http://reviews.llvm.org/D5518






More information about the llvm-commits mailing list