LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 47668 - foldSelectICmpAndAnd should check whether the shift amount is less than bitwidth
Summary: foldSelectICmpAndAnd should check whether the shift amount is less than bitwidth
Status: NEW
Alias: None
Product: libraries
Classification: Unclassified
Component: Scalar Optimizations (show other bugs)
Version: trunk
Hardware: PC MacOS X
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-09-28 07:27 PDT by Juneyoung Lee
Modified: 2020-09-28 10:34 PDT (History)
5 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Juneyoung Lee 2020-09-28 07:27:39 PDT
File: test/Transforms/InstCombine/select-of-bittest.ll 
```
define i32 @f_var2(i32 %arg, i32 %arg1) {
%0:
  %tmp = and i32 %arg, 1
  %tmp2 = icmp eq i32 %tmp, 0
  %tmp3 = lshr i32 %arg, %arg1
  %tmp4 = and i32 %tmp3, 1
  %tmp5 = select i1 %tmp2, i32 %tmp4, i32 1
  ret i32 %tmp5
}
=>
define i32 @f_var2(i32 %arg, i32 %arg1) {
%0:
  %1 = shl i32 1, %arg1
  %2 = or i32 %1, 1
  %3 = and i32 %2, %arg
  %4 = icmp ne i32 %3, 0
  %tmp5 = zext i1 %4 to i32
  ret i32 %tmp5
}
Transformation doesn't verify!
ERROR: Target is more poisonous than source

Example:
i32 %arg = #x00000001 (1)
i32 %arg1 = poison

Source:
i32 %tmp = #x00000001 (1)
i1 %tmp2 = #x0 (0)
i32 %tmp3 = poison
i32 %tmp4 = poison
i32 %tmp5 = #x00000001 (1)

Target:
i32 %1 = poison
i32 %2 = poison
i32 %3 = poison
i1 %4 = poison
i32 %tmp5 = poison
Source value: #x00000001 (1)
Target value: poison
```

Relevant revision: https://reviews.llvm.org/D45108
The revision includes Alive proof, but its precondition wasn't encoded.
I'll make a patch for this.
Comment 1 Juneyoung Lee 2020-09-28 10:34:16 PDT
Made a patch here: https://reviews.llvm.org/D88432